Cod sursa(job #1131164)

Utilizator FayedStratulat Alexandru Fayed Data 28 februarie 2014 18:13:37
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.29 kb
#include <cstdio>
#include <vector>
#define NMAX 1000007
using namespace std;

vector < int > Hash[NMAX];
int n;

bool searchHash(int x){

    int key = x%NMAX;

        for(vector < int > ::iterator it = Hash[key].begin();it!=Hash[key].end();++it)

            if(*it == x)

                    return true;
return false;
}

void addHash(int x){

    int key = x%NMAX;

        if(!searchHash(x))
            Hash[key].push_back(x);
}

void deleteHash(int x){

    int key = x%NMAX;

        for(vector < int > ::iterator it = Hash[key].begin();it!=Hash[key].end();++it)

            if(*it == x){

                Hash[key].erase(it);
                return;
            }
}

void solve(){

    int option;
    int x;

    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d",&n);

        while(n){

            scanf("%d%d",&option,&x);

                switch(option){

                    case 1 : addHash(x);
                             break;

                    case 2: deleteHash(x);
                             break;

                    case 3: printf("%d\n",searchHash(x));
                             break;
                }

        --n;
        }
}

int main(){

    solve();

return 0;
}