Cod sursa(job #1092513)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 27 ianuarie 2014 10:14:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <vector>
#define Key 100001
#define pb push_back
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

int N;
vector < int > Hash[Key];

bool Find(int x)
{
    int L= x % Key;
    vector < int > :: iterator it;
    for(it=Hash[L].begin();it!=Hash[L].end();++it)
        if( x == *it)return 1;
    return 0;
}

void Add(int x)
{
    if ( !Find(x) ) Hash[x % Key].pb(x);
}

void Delete(int x)
{
    int L = x % Key;
    vector<int>::iterator it;
    for (it=Hash[L].begin(); it!=Hash[L].end();++it)
        if (x == *it)
        {
            Hash[L].erase(it);
            return;
        }
}


int main()
{
    f>>N;
    for (int i=1;i<=N;++i)
    {
        int tip,x;
        f>>tip>>x;
        if (tip==1)Add(x);
        if (tip==2)Delete(x);
        if (tip==3)g<<Find(x)<<'\n';
    }
    f.close();g.close();
    return 0;
}