Pagini recente » Cod sursa (job #3174724) | Cod sursa (job #814774) | Cod sursa (job #2315502) | Cod sursa (job #312766) | Cod sursa (job #611738)
Cod sursa(job #611738)
#include<cstdio>
#define infile "hashuri.in"
#define outfile "hashuri.out"
#define mod 666013
using namespace std;
typedef struct nod {
int inf;
nod *urm;
} *pnod;
pnod L[mod];
void add(int x)
{
int list = x % mod;
pnod p = new nod;
p->inf = x;
p->urm = L[list];
L[list] = p;
}
void erase(int x)
{
int list = x%mod;
if(!L[list])
return;
pnod p = L[list];
if(L[list]->inf == x)
{
L[list] = L[list]->urm;
delete p;
return;
}
while(p->urm->inf != x)
p = p->urm;
pnod q = p->urm;
p = p->urm->urm;
delete q;
}
int find(int x)
{
int list = x%mod;
pnod p = L[list];
while(p)
{
if(p->inf == x)
return 1;
p = p->urm;
}
return 0;
}
int main()
{
freopen(infile,"r",stdin);
freopen(outfile,"w",stdout);
int op, x, n;
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&op,&x);
switch (op)
{
case 1: add(x); break;
case 2: erase(x); break;
case 3: printf("%d\n", find(x) ); break;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}