Cod sursa(job #1018296)

Utilizator ZanarokStefan Mocanu Zanarok Data 29 octombrie 2013 11:24:33
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.12 kb
#include <iostream>
#include <cstdio>
#include <vector>

#define P 19391

using namespace std;

int n;
vector <vector <int> > hesh;

int cauta(int b)
{
    int a=b%P;
    int len=hesh[a].size();
    for(int k=0;k<len;k++)
        if(hesh[a][k]==b)
            return 1;
    return 0;
}
int adauga(int b)
{
    int a=b%P;
    int len=hesh[a].size();
    for(int k=0;k<len;k++)
        if(hesh[a][k]==b)
            return 1;
    hesh[a].push_back(b);
    return 0;
}
int sterge(int b)
{
    int a=b%P;
    int  len=hesh[a].size();
    for(int k=0;k<len;k++)
        if(hesh[a][k]==b)
            {hesh[a].erase(hesh[a].begin()+k);return 0;}
    return 1;
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    cin>>n;
    int a,b;
    vector <int> aux;
    hesh.assign(P,aux);
    for(int k=1;k<=n;k++)
    {
        scanf("%d %d",&a,&b);
        if(a==1)
            adauga(b);
        else
            if(a==2)
                sterge(b);
            else
                if(a==3)
                    cout<<cauta(b)<<endl;
    }
    return 0;
}