Pagini recente » Cod sursa (job #929619) | Cod sursa (job #2496643) | Cod sursa (job #3185966) | Cod sursa (job #1838235) | Cod sursa (job #248827)
Cod sursa(job #248827)
#include <stdio.h>
struct nod{
long a;
nod *adr;
} *prim[666030], *sf[666030]; //666030
long X=666013;
void f1(long t)
{
int p=1;
long rest=t%X;
nod *aux;
aux=new nod;
aux->a=t;
aux->adr=NULL;
if (prim[rest]==NULL)
{
prim[rest]=aux;
}
else
{
//verif - go
aux=new nod;
aux=prim[rest];
while (aux!=NULL&&p)
{
if (aux->a==t) p=0;
aux=aux->adr;
}
if (p) {
aux=new nod;
aux->a=t;
aux->adr=NULL;
sf[rest]->adr=aux;
sf[rest]=aux;
}
}
}
void f2(long t)
{
nod *aux;
int p=0;
long rest=t%X;
if (prim[rest]!=NULL)
{
if (prim[rest]->adr==NULL&&prim[rest]->a==t)
{
prim[rest]=NULL;
sf[rest]=NULL;
}
aux=new nod;
aux=prim[rest];
while (aux->adr!=NULL&&!p)
{
if (aux->adr->a==t)
{
if (aux->adr->adr==NULL)
{
aux->adr=NULL;
sf[rest]=aux;
}
else
{
aux->adr=aux->adr->adr;
}
}
aux=aux->adr;
}
}
}
int f3(long t)
{
long rest=t%X;
nod *aux;
int p=0;
if (prim[rest]==NULL)
return 0;
else
{
aux=new nod;
aux=prim[rest];
while (aux!=NULL&&!p)
{
if (aux->a==t) p=1;
aux=aux->adr;
}
return p;
}
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
long n,i,x;
int tip;
scanf("%ld",&n);
for (i=1;i<=n;i++)
{
scanf("%d %ld",&tip,&x);
if (tip==1) f1(x);
if (tip==2) f2(x);
if (tip==3) printf("%d\n",f3(x));
}
return 0;
}