Cod sursa(job #1060582)

Utilizator gogol100vrabie gelu gogol100 Data 18 decembrie 2013 09:45:09
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
//
//  main.cpp
//  hash
//
//  Created by Gelu Vrabie on 12/18/13.
//  Copyright (c) 2013 Gelu Vrabie. All rights reserved.
//

#include <fstream>
#include <list>
using namespace std;
const int MOD=66013;
typedef list<int> hesh;
hesh ht[MOD];
typedef hesh::iterator hit;

hit find(int x){
    for(hit i=ht[x%MOD].begin();i!=ht[x%MOD].end();i++)
        if(x==*i)
            return i;
    return ht[x%MOD].end();
}
int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int n,a,x,j;
    f>>n;
    for(j=1;j<=n;j++)
    {
        f>>a>>x;
        if(a==1 && find(x)==ht[x%MOD].end()) ht[x%MOD].push_back(x);
        else if(a==2 && find(x)!=ht[x%MOD].end()) ht[x%MOD].erase(find(x));
        else if(a==3 && find(x)!=ht[x%MOD].end()) g<<1<<endl;
        else if(a==3) g<<0<<endl;
    }
    return 0;
}