Pagini recente » Cod sursa (job #1681539) | Cod sursa (job #2520005) | Arhiva de probleme | Cod sursa (job #71243) | Cod sursa (job #245089)
Cod sursa(job #245089)
#include <stdio.h>
#define max 666013
struct nod
{
int x;
nod *urm;
};
nod *A[max];
void add(int y)
{
nod *q = A[y%max];
int ok=1;
while (ok && q!=NULL) if (q->x!=y) q=q->urm;
else ok=0;
if (ok)
{
q = new nod;
q->x = y;
q->urm = A[y%max];
A[y%max] = q;
}
}
void erase(int y)
{
nod *q = A[y%max],*r;
int ok=1;
if (q->x==y) A[y%max]=A[y%max]->urm,ok=0;
while (ok && q!=NULL)
{
r = q;
q = q->urm;
if (q->x==y) r->urm=q->urm,ok=0;
}
}
int verif(int y)
{
nod *q = A[y%max];
int ok=0;
while (!ok && q!=NULL) if (q->x!=y) q=q->urm;
else ok=1;
return ok;
}
int main()
{
FILE *in = fopen("hashuri.in","r");
FILE *out = fopen("hashuri.out","w");
int n,i,x,y;
fscanf(in,"%d",&n);
for (i=1;i<=n;i++)
{
fscanf(in,"%d %d",&x,&y);
if (x==1) add(y);
if (x==2) erase(y);
if (x==3) fprintf(out,"%d\n",verif(y));
}
}