Pagini recente » Cod sursa (job #2459247) | Cod sursa (job #1612237) | Cod sursa (job #1922001) | Cod sursa (job #1141226) | Cod sursa (job #2938612)
#include<fstream>
#include<cmath>
//#include<iostream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
double y=(sqrt(5)-1)/2;
int m;
struct nod{
int info=0;
nod *urm=NULL;
}*h[50002];
void inserare(nod *&prim,int val)
{
nod*t=new nod;
t->info=val;
t->urm=prim;
prim=t;
}
int get_index(int x)
{
return m*(x*y-floor(x*y));
}
void cautare(nod *prim,int val)
{
int gasit=0;
if(prim==NULL)
cout<<"0\n";
else
{
nod *p=prim;
while(p!=NULL)
{
if(p->info==val)
{gasit=1;break;}
p=p->urm;
}
if(gasit==1)
cout<<"1\n";
else
cout<<"0\n";
}
}
void stergere(nod *&prim,int val)
{
if(prim==NULL)
return ;
nod *t;
if(prim->info==val)
{
t=prim;
prim=prim->urm;
delete t;
return ;
}
t=prim;
while(t->info!=val&&t->urm!=NULL)
{
t=t->urm;
}
if(t->info!=val)
return;
nod *p=t;
p=p->urm;
delete t;
}
int main()
{
int n;
m=50000;
cin>>n;
int x,j;
for(;n;n--)
{
cin>>x>>j;
if(x==1)
inserare(h[get_index(j)],j);
else
if(x==2)
{
stergere(h[get_index(j)],j);
}
else if(x==3)
cautare(h[get_index(j)],j);
}
}