Cod sursa(job #316743)

Utilizator DraStiKDragos Oprica DraStiK Data 20 mai 2009 22:22:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include <stdio.h>
#define DIM 1234561
struct nod {int x;
            nod *urm;} *lst[DIM];
int n;
void baga (int a,int b)
{
    nod *p;
    for (p=lst[b]; p; p=p->urm)
        if (p->x==a)
            return ;
    p=new nod;
    p->x=a;
    p->urm=lst[b];
    lst[b]=p;
}
void erase (int a,int b)
{
    nod *p,*q;
    if (!lst[b])
        return ;
	if (lst[b]->x==a)
    {
        p=lst[b];
        lst[b]=p->urm;
        delete p;
        return ;
    }
    for (p=lst[b], q=NULL; p; q=p, p=p->urm)
        if (p->x==a)
        {
			q->urm=p->urm;
			delete p;
            return;
        }
}
bool find (int a,int b)
{
    nod *p;
    for (p=lst[b]; p; p=p->urm)
        if (p->x==a)
            return 1;
    return 0;
}
int main ()
{
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);
    int i,x,y;
    scanf ("%d",&n);
    for (i=1; i<=n; ++i)
    {
		scanf ("%d%d",&x,&y);
        if (x==1)
			baga (y,y%DIM);
		else if (x==2)
            erase (y,y%DIM);
		else if (x==3)
			printf ("%d\n",find (y,y%DIM));
    }
    return 0;
}