Pagini recente » Cod sursa (job #1616198) | Cod sursa (job #1816175) | Cod sursa (job #1955733) | Cod sursa (job #1699624) | Cod sursa (job #1741475)
using namespace std;
#include<fstream>
#define P 333331
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct hash {int inf; hash *urm;};
hash *H[P];
int n;
void insert(int x)
{
hash *p;
if(H[x%P]==NULL)
{
H[x%P]=new hash;
H[x%P]->inf=x;
H[x%P]->urm=NULL;
}
else
{
p=H[x%P]->urm;
while(p==NULL) p=p->urm;
p=new hash;
p->inf=x;
p->urm=NULL;
}
}
void del(int x)
{
hash *p,*q;
p=H[x%P];
if(p!=NULL && p->inf==x)
{
H[x%P]=H[x%P]->urm;
delete p;
}
else if (p!=NULL)
{
while(p->urm!=NULL && p->urm->inf!=x) p=p->urm;
if(p->urm->inf==x)
{
q=p->urm;
p->urm=p->urm->urm;
delete q;
}
}
}
bool search (int x)
{
hash *p;
if(H[x%P]==NULL) return 0;
p=H[x%P];
while(p->inf!=x && p->urm!=NULL) p=p->urm;
if(p->inf==x) return 1;
return 0;
}
int main()
{
int o,x,i;
f>>n;
for(i=0; i<P; i++) H[i]=NULL;
while(n--)
{
f>>o>>x;
if(o==1) insert(x);
else if(o==2) del(x);
else g<<search(x)<<'\n';
}
return 0;
}