Pagini recente » Cod sursa (job #2344545) | Cod sursa (job #1378787) | Cod sursa (job #2905485) | Cod sursa (job #740479) | Cod sursa (job #808447)
Cod sursa(job #808447)
#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");
int n;
void insert (long long x)
{
long long k; nod *q;
k=x%mod;
int ok=1;
for ( q=lista[k];q&&ok;q=q->urm)
if (q->info == x) ok=0;
if (ok)
{
nod *p= new nod;
p ->info=x;
p->urm=lista[k];
lista[k]=p;
}
}
int find (long long x)
{
long k=x%mod;
if ( lista[k]==NULL) return 0 ;
if (lista[k]->info==x) return 1;
nod *p=lista[k];
for (p=lista[k];p;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()
{ int op;
long long x;
in>>n;
while (n--)
{
in>>op>>x;
if (op==1)
{
insert(x);
}
else
if (op==2)
{
deletes(x);
}
else
if (op==3)
out<<find(x)<<endl;
}
return 0;
}