Pagini recente » Cod sursa (job #255440) | Cod sursa (job #1479920) | Cod sursa (job #1410014) | Istoria paginii runda/infinity-2022-8 | Cod sursa (job #353183)
Cod sursa(job #353183)
#include<stdio.h>
#define DIM 1234567
struct nod
{
int x;
nod *urm;
} *lst[DIM];
int baga (int a,int b)
{
nod *p=new nod;
nod *q;
for(q=lst[a];q;q=q->urm)
if(q->x==b)
return 0;
p->x=b;
p->urm=lst[a];
lst[a]=p;
}
void sterge (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 cauta (int a,int b)
{
nod *p;
for(p=lst[a];p;p=p->urm)
if(p->x==b)
return 1;
return 0;
}
int main ()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int i,n,q,x;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%d%d",&q,&x);
if(q==1)
baga (x%DIM,x);
else if (q==2)
sterge (x%DIM,x);
else
printf("%d\n",cauta (x%DIM,x));
}
return 0;
}