Cod sursa(job #1404055)

Utilizator emanuel_rRamneantu Emanuel emanuel_r Data 27 martie 2015 19:06:50
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

int N;
vector<int> G[MOD];

int Find(int Value)
{
    int List = Value % MOD;
    for(int i = 0; i< (int) G[List].size(); i++)
        {
            if(G[List][i]==Value)
                return i;
        }
    return -1;
}

void Insert(int Value)
{
    int List = Value % MOD;
    int P = Find(Value);
    if(P == -1)
        G[List].push_back(Value);
}

void Delete(int Value)
{
    int List = Value % MOD;
    int P = Find(Value);

    if(P != -1)
        {
            G[List].erase(G[List].begin() + P);
        }
}



int main()
{
    fin>>N;
    while(N--)
    {
        int op,x;
        fin>>op>>x;
        if(op==1)
           Insert(x);
        if(op==2)
            Delete(x);
        if(op==3)
            fout<<(Find(x) != -1)<<"\n";


    }
    return 0;
}