Cod sursa(job #1777967)

Utilizator tudorgalatanRoman Tudor tudorgalatan Data 13 octombrie 2016 09:35:05
Problema Hashuri Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>

using namespace std;

unsigned int N;
unsigned short int op;
unsigned int x;

unsigned int V[1000001];
bool ok;
unsigned int i, j, k, start;

int main ()
{
    ifstream fin ("hashuri.in");
    fin >> N;
    ofstream fout ("hashuri.out");
    for (i=1; i<=N; i++)
    {
        fin >> op >> x;
        if (op == 1)
        {
            k++;
            V[k] = x;
        }
        else if (op == 2)
        {
            for (j=1; j<=k; j++)
                if (V[j] == x)
                    start = j;
            for (j=start; j<=k; j++)
                V[j] = V[j+1];
            k--;
        }
        else
        {
            ok = 0;
            for (j=1; j<=k; j++)
                if (V[j] == x)
                    ok = 1;
            if (ok == 1)
                fout << 1 << '\n';
            else
                fout << 0 << '\n';
        }
    }
    fin.close();
    fout.close();
    return 0;
}