Pagini recente » Cod sursa (job #2071777) | Cod sursa (job #2016726) | Cod sursa (job #2109077) | Cod sursa (job #372212) | Cod sursa (job #248870)
Cod sursa(job #248870)
#include <stdio.h>
struct nod{
int a;
nod *adr;
} *prim[500009]; //666030
long X=500009; //666013 ; 179533
void f1(int t)
{
int p=1;
int rest=t%X;
nod *aux;
if (prim[rest]==NULL)
{
aux=new nod;
aux->a=t;
aux->adr=NULL;
prim[rest]=aux;
}
else
{
//verif - go
nod *sf;
aux=new nod;
aux=prim[rest];
while (aux!=NULL&&p)
{
if (aux->a==t) p=0;
if (aux->adr==NULL) sf=aux;
aux=aux->adr;
}
if (p) {
aux=new nod;
aux->a=t;
aux->adr=NULL;
sf->adr=aux;
}
}
}
void f2(int t)
{
nod *aux;
int p=0;
int rest=t%X;
if (prim[rest]!=NULL)
{
if (prim[rest]->adr==NULL&&prim[rest]->a==t)
{
prim[rest]=NULL;
}
else
{
if (prim[rest]->a==t&&prim[rest]->adr->adr==NULL)
{
prim[rest]=prim[rest]->adr;
}
else
{
aux=new nod;
aux=prim[rest];
while (aux->adr!=NULL&&!p)
{
if (aux->adr->a==t)
{
if (aux->adr->adr==NULL)
{
aux->adr=NULL;
}
else
{
aux->adr=aux->adr->adr;
}
}
else aux=aux->adr;
}
}
}
}
}
int f3(int t)
{
int 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;
}