Pagini recente » Cod sursa (job #312259) | Cod sursa (job #1780506) | Cod sursa (job #2775641) | Cod sursa (job #141054) | Cod sursa (job #2846261)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int MAX=1e6+5;
const int P=666013;
int n,op,x;
struct nod
{
int info;
nod *urm;
}*H[P];
void adauga(int x)
{
int xmod=x%P;
nod *u=new nod;
u->info=x;
u->urm=H[xmod];
H[xmod]=u;
}
void sterge(int x)
{
int xmod=x%P;
nod *p=H[xmod];
if(p && p->info==x)
if(p->urm)
{
nod *u=p;
p=p->urm;
delete u;
}
else
{
p->info=-1;
p->urm=NULL;
}
nod *ant=p;
if(p)
p=p->urm;
while(p)
{
if(p->info==x)
{
ant->urm=p->urm;
delete p;
return;
}
p=p->urm;
}
}
bool apare(int x)
{
int xmod=x%P;
nod *p=H[xmod];
while(p)
{
if(p->info==x)
return 1;
p=p->urm;
}
return 0;
}
int main()
{
fin >> n;
while(n--)
{
fin >> op >> x;
switch(op)
{
case 1 : if(!apare(x)) adauga(x); break;
case 2 : if(apare(x)) sterge(x); break;
case 3 : fout << apare(x) << '\n'; break;
}
}
return 0;
}