Pagini recente » Cod sursa (job #3165667) | Cod sursa (job #2692742) | Cod sursa (job #1717689) | Cod sursa (job #727089) | Cod sursa (job #625654)
Cod sursa(job #625654)
#include<stdio.h>
# define MOD 666013
struct point {int inf; point *leg;} *H[700000];
point *p,*q,*u,*t;
int i,ind,op,x,n;
bool ok;
void inserare(int x)
{
point *p=new point;
ind = x% MOD;
p->inf=x;
p->leg=H[ind];
H[ind]=p;
}
void stergere(int x)
{
ind=x%MOD;
p=H[ind]; u=H[ind];
while (p->inf !=x && p!=NULL)
{
u=p;
p=p->leg;
}
if (p)
{
if (u==p)
{
H[ind]=H[ind]->leg;
delete p;
}
else
{
t=p;
u->leg=p->leg;
delete t;
}
}
}
bool cautare(int x)
{
int i;
ind=x%MOD;
p=H[ind];
while (p!=NULL)
{
if (p->inf==x)
{
return true;
}
else p=p->leg;
}
return false;
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d\n",&n);
for (i=1; i<=n; i++)
{
scanf("%d %d\n",&op,&x);
if (op==1)
inserare(x);
else
if (op==2)
{
ok=cautare(x);
if (ok)
stergere(x);
}
else
{
ok=cautare(x);
if (ok) printf("1\n"); else printf("0\n");
}
}
return 0;
}