Pagini recente » Cod sursa (job #3030504) | Cod sursa (job #669649) | Cod sursa (job #2831862) | Cod sursa (job #627842) | Cod sursa (job #1045655)
#include <iostream>
#include <fstream>
using namespace std;
long poz=666013;
struct nod
{
int val;
nod *urm;
}*my_hash[666013];
void adaugare(nod *&p, int n)
{
if (p==NULL){
p=new nod;
p->val=n;
p->urm=NULL;
}
else{
nod *q=new nod;
q->urm=p;
q->val=n;
p=q;
}
}
void stergere(nod *&p, int x)
{
nod *q,*t=p;
while (t&&t->val!=x){
q=t;
t=t->urm;
}
if (t){
if (t==p){
p=p->urm;
delete t;
}
else
{
q->urm=t->urm;
delete t;
}
}
}
int my_find(nod *prim,int x)
{
while (prim&&prim->val!=x){
prim=prim->urm;
}
if (prim)
return 1;
return 0;
}
int main()
{
long n,x,i,answer,pozitie;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
for (i=0;i<n;i++)
{
f>>answer;
f>>x;
pozitie=x%poz;
if (answer==1){
adaugare(my_hash[pozitie],x);
}
else if (answer==2)
stergere(my_hash[pozitie],x);
else {
if (my_find(my_hash[pozitie],x))
g<<1<<endl;
else
g<<0<<endl;
}
}
return 0;
}