Cod sursa(job #269959)

Utilizator mihai0110Bivol Mihai mihai0110 Data 3 martie 2009 17:09:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include<stdio.h>
#define MOD 666013

struct nod{int x;nod *urm;};
nod *v[MOD+1];
int n,x,op;

int find(int x,int rest)
{
    nod *q;
    for(q=v[rest];q;q=q->urm)
        if(q->x==x)
            return 1;
    return 0;
}

void add(int x,int rest)
{
    nod *q=new nod;
    q->x=x;
    q->urm=v[rest];
    v[rest]=q;
}

void remove(int x,int rest)
{
    nod *q;
    for(q=v[rest];q;q=q->urm)
        if(q->x==x)
        {
            q->x=0;
            return;
        }
}

int main(void)
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d",&op,&x);
        if(op==1 && !find(x,x%MOD))
            add(x,x%MOD);
        if(op==2)
            remove(x,x%MOD);
        if(op==3)
            printf("%d\n",find(x,x%MOD));
    }
    return 0;
}