Pagini recente » Cod sursa (job #3193777) | Cod sursa (job #2320755) | Cod sursa (job #898865)
Cod sursa(job #898865)
#include<cstdio>
#include<cmath>
using namespace std;
int nr,op,n;
const int cheie=66601;
struct list
{
int val;
list *d;
};
list *hash[66601];
inline int h(int x)
{
return ((int)((float)x*(float)(sqrt(5)-2))%cheie);
}
void sterg(int poz, int x)
{
list *aux;
aux=new list;
aux=hash[poz];
if(aux->val==x)
{
hash[poz]=hash[poz]->d;
delete aux;
}
else{
while(aux!=0&&aux->d->val!=x)
aux=aux->d;
list *cpy;
cpy=aux->d;
aux->d=cpy->d;
delete cpy;}
}
int verif(int poz, int x)
{
list *aux;
aux=new list;
aux=hash[poz];
while(aux!=0&&aux->d!=0&&aux->d->val!=x)
aux=aux->d;
if(aux!=0&&aux->d!=0&&aux->d->val==x)
return 1;
else if(aux!=0&&aux->val==x)
return 1;
return 0;
}
void adaug(int poz, int x)
{
list *aux;
aux=new list;
aux->d=hash[poz];
aux->val=x;
hash[poz]=aux;
}
void citire()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d", &n);
for(int i=0;i<66601;++i)
hash[i]=0;
for(int i=1;i<=n;++i)
{
scanf("%d%d", &op, &nr);
if(op==1)
if(!verif(h(nr),nr))
adaug(h(nr),nr);
else if(op==3)
printf("%d\n",verif(h(nr),nr));
else if(verif(h(nr),nr))
sterg(h(nr),nr);
}
}
int main()
{
citire();
return 0;
}