Pagini recente » Cod sursa (job #1545126) | Cod sursa (job #2914121) | Cod sursa (job #1476366) | Cod sursa (job #2312330) | Cod sursa (job #808432)
Cod sursa(job #808432)
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
#define mod 666013
struct nod
{ long info;
nod *urm;
} *lista[mod];
ifstream in("hashuri.in");
ofstream out("hashuri.out");
long n;
void insert (long x)
{
nod * p; nod *q;
int ok=1;
int k=x%mod;
for (p=lista[k];p&&ok;p=p->urm)
if (p->info==k)
{ ok=0;
break;
}
if (ok)
{
q= new nod;
q->info=x;
q->urm=lista[k];
lista[k]=q;
}
}
long find (long x)
{
long k=x%mod;
if ( lista[k]==NULL) return 0 ;
if (lista[k]->info==x) return 1;
nod *p=lista[k];
while (p->urm)
{
p=p->urm;
if (p->info==x) return 1;
}
return 0;
}
void deletes (long x)
{ nod *p; nod *q;
long k=x%mod;
p=lista[k];
if (p)
{
if (p->info==x)
{ lista[k]=p->urm;
delete p;
}
else
{
while (p->urm && p->urm->info !=x)
p=p->urm;
if (p->urm)
{
q=p->urm;
p->urm=q->urm;
delete q;
}
}
}
}
int main()
{ long c;
long x;
in>>n;
while (n--)
{
in>>c>>x;
if (c==1)
{
insert(x);
}
else
if (c==2)
{
deletes(x);
}
else
if (c==3)
out<<find(x)<<endl;
}
return 0;
}