Pagini recente » Cod sursa (job #1541687) | Cod sursa (job #783809) | Cod sursa (job #1575411) | Cod sursa (job #2516629) | Cod sursa (job #316739)
Cod sursa(job #316739)
#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)
{
lst[b]=lst[b]->urm;
delete p;
}
else
for (p=q=lst[b] ; ; p=q, q=q->urm);
if (p->x==a)
{
q->urm=p->urm;
delete q;
return ;
}
}
int 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
printf ("%d\n",find (y,y%DIM));
}
return 0;
}