Pagini recente » Cod sursa (job #2938428) | Cod sursa (job #813936) | Cod sursa (job #2433684) | Cod sursa (job #2128345) | Cod sursa (job #245086)
Cod sursa(job #245086)
#include <stdio.h>
#define max 100013
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];
int ok=1;
if (q->x==y) A[y%max]=A[y%max]->urm,ok=0;
while (ok && q->urm!=NULL)
if (q->urm->x==y) q->urm = q->urm->urm,ok=0;
else q = q->urm;
}
int verif(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==0) ok=1;
else ok=0;
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));
}
}