Pagini recente » Cod sursa (job #3141798) | Cod sursa (job #3273515) | Cod sursa (job #1121634) | Cod sursa (job #291686) | Cod sursa (job #267521)
Cod sursa(job #267521)
#include <stdio.h>
#include <stdlib.h>
#define MOD 610107
typedef struct nod
{
long v;
nod *urm;
} *pnod;
pnod list[MOD];
long n;
void baga(long poz, long x)
{
pnod aux = new nod;
aux -> v = x;
aux -> urm = list[poz];
list[poz] = aux;
}
int find(long poz, long x)
{
pnod it;
for(it = list[poz]; it != NULL; it = it -> urm)
if(it -> v == x)
return 1;
return 0;
}
void remove(long poz, long x)
{
pnod it, last;
if(list[poz] -> v == x)
{
it = list[poz] -> urm;
delete list[poz];
list[poz] = it;
return ;
}
else
{
last = list[poz];
for(it = list[poz]; it != NULL; it = it -> urm)
{
if(it -> v == x)
{
last -> urm = it -> urm;
delete it;
it = NULL;
return ;
}
last = it;
}
}
}
int main()
{
long o, x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%ld", &n);
while(n--)
{
scanf("%ld %ld", &o, &x);
if(o == 1)
{
if(!find(x%MOD, x))
baga(x%MOD, x);
}
else if(o == 2)
remove(x%MOD, x);
else
printf("%d\n", find(x%MOD, x));
}
return 0;
}