Pagini recente » Cod sursa (job #1355835) | Cod sursa (job #2828960) | Cod sursa (job #2706114) | Cod sursa (job #520398) | Cod sursa (job #808421)
Cod sursa(job #808421)
#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)
{
long k;
k=x%mod;
nod *p= new nod;
p ->info=x;
p->urm=lista[k];
lista[k]=p;
}
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)
{
if (find(x)==0) insert(x);
}
else
if (c==2)
{
deletes(x);
}
else
if (c==3)
out<<find(x)<<endl;
}
return 0;
}