Pagini recente » Cod sursa (job #1108431) | Cod sursa (job #972941) | Cod sursa (job #87853) | Cod sursa (job #848128) | Cod sursa (job #244535)
Cod sursa(job #244535)
#include <stdio.h>
struct nod{
long a;
nod *adr;
} *prim[666015]; //666015
long X=666013;
void f1(long t)
{
int p=1;
long rest=t%X;
nod *aux,*sf;
if (prim[rest]==NULL)
{
aux=new nod;
aux->a=t;
aux->adr=NULL;
prim[rest]=aux;
}
else
{
//verif - go
aux=new nod;
aux=prim[rest];
while (aux!=NULL)
{
if (aux->a==t) p=0;
if (aux->adr==NULL) sf=aux->adr;
aux=aux->adr;
}
if (p) {
aux=new nod;
aux->a=t;
aux->adr=NULL;
sf->adr=aux;
}
}
}
void f2(long t)
{
long rest=t%X;
nod *aux,*aux2;
if (prim[rest]!=NULL)
{
aux=new nod;
aux=prim[rest];
if (aux->adr->a==0)
{
aux=NULL;
prim[rest]=aux;
}
else
while (aux!=NULL)
{
if (aux->a==t)
aux2->adr=aux->adr;
aux2=aux;
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)
{
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;
}