Pagini recente » Rating as arf (az234) | Cod sursa (job #962012) | Cod sursa (job #2450802) | Profil adela.balasa | Cod sursa (job #1083245)
#include<iostream>
#include<fstream>
using namespace std;
#define q 237019
typedef struct hash
{
int val;
hash *urm;
} H;
H *a[q+10];
int main()
{
int i,n,x,op,ok;
H *p,*nou,*t;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
for (i=0; i<=q; i++)
{a[i]=new H;
a[i]->urm=NULL;}
f>>n;
for (i=1; i<=n; i++)
{f>>op>>x;
if (op==1)
{ok=1;
p=a[x%q];
while (p->urm!=NULL)
{if (p->urm->val==x) ok=0;
p=p->urm;}
if (ok)
{nou=new H;
nou->val=x;
nou->urm=NULL;
p->urm=nou;}
}
else if (op==2)
{p=a[x%q];
if (p->urm!=NULL)
{while (p->urm->val!=x && p->urm!=NULL)
{p=p->urm;
if (p->urm==NULL && p->val!=x) break;}
if (p->urm!=NULL)
{t=p->urm;
p->urm=t->urm;
delete t;}
}
}
else
{ok=0;
p=a[x%q];
if (p->urm!=NULL)
while (p->urm!=NULL && p->urm->val!=x)
p=p->urm;
if (p->urm!=NULL) ok=1;
g<<ok<<"\n";}
}
return 0;
}