Cod sursa(job #1060583)

Utilizator tannous.marcTannous Marc tannous.marc Data 18 decembrie 2013 09:45:38
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 kb
#include <fstream>
#include <list>
using namespace std;
const int MOD=666013;
typedef list<int> hesh;
typedef hesh::iterator hit;
hesh ht[MOD+10];
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()
{
    int n;
    ifstream in("hashuri.in");
    ofstream out("hashuri.out");
        in>>n;
    int op,param;
            for(int i=1;i<=n;i++)
            {
                in>>op>>param;
                hit cnt=find(param);
                    if(op==1)
                        {
                            if(cnt==ht[param%MOD].end())
                                ht[param%MOD].push_back(param);
                        }
                    else if(op==2)
                        {
                            if(cnt!=ht[param%MOD].end())
                                ht[param%MOD].erase(cnt);
                        }
                    else if(op==3)
                        {
                            if(cnt!=ht[param%MOD].end())
                                out<<1<<endl;
                            else out<<0<<endl;
                        }
            }
    return 0;
}