Cod sursa(job #1060589)

Utilizator tannous.marcTannous Marc tannous.marc Data 18 decembrie 2013 09:53:31
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.27 kb
#include <cstdio>
#include <list>
using namespace std;
const int MOD=36013;
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;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
        scanf("%d", &n);
    int op,param;
            for(int i=1;i<=n;i++)
            {
                scanf("%d %d",&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())
                                printf("%d \n",1);
                            else printf("%d \n",0);
                        }
            }
    return 0;
}