Cod sursa(job #1191018)

Utilizator cristigrigoreGrigore Cristan Andrei cristigrigore Data 26 mai 2014 11:24:19
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
#include <cstdio>
#define MOD 666013
using namespace std;
int i,j,m,n,op,x,ind;
struct point
{
    int inf;
    point *leg;
};
point *p,*prim,*u,*t,*h[1000000],*q;
bool cauta(int x,int ind)
{
    for(t=h[ind]; t!=NULL; t=t->leg)
    if(t->inf==x) return true;
    return false;
}
point *del(int x, int ind)
{
    point *t;
    u=NULL;
    p=h[ind];
    while(p!=NULL && p->inf!=x)
    {
        u=p;
        p=p->leg;
    }
    if(h[ind]!=NULL && h[ind]->inf==x)
    {
        t=h[ind];
        h[ind]=h[ind]->leg;
        delete t;
    }
    else if(p!=NULL)
    {
        u->leg=p->leg;
        delete p;
    }
    return h[ind];
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for(i=1; i<1000000; i++)
    h[i]=NULL;
    for(i=1; i<=n; i++)
    {
        scanf("%d %d",&op,&x);
        ind=x%MOD;
        if(op==1 && !cauta(x,ind))
        {
            q=new point;
            q->leg=h[ind];
            q->inf=x;
            h[ind]=q;
        }
        else if(op==2) h[ind]=del(x,ind);
        else if(op==3)
        {
            if(cauta(x,ind))printf("1\n");
            else printf("0\n");
        }
    }
    return 0;
}