Pagini recente » Cod sursa (job #2481840) | Cod sursa (job #281390) | Cod sursa (job #3178891) | Cod sursa (job #961058) | Cod sursa (job #373364)
Cod sursa(job #373364)
using namespace std;
#include <cstdio>
#define P 30103
struct nod{
int info;
nod *next;
};
nod * hash[P+10];
int n;
int Apartine(int x){
int poz=x%P;
nod * p=hash[poz];
while(p)
if(p->info==x)
return 1;
else
p=p->next;
return 0;
}
void Adauga(int x){
if(Apartine(x))
return ;
int poz=x%P;
nod *p=new nod;
p->info = x;
p->next=hash[poz];
hash[poz]=p;
}
void Sterge(int x){
int poz=x%P;
nod *p=hash[poz], *q;
if(!p)
return ;
if(p->info==x){
q=p;
p=p->next;
delete q;
}
else{
while(p->next && p->next->info!=x)
p=p->next;
if(!(p->next))
return;
q=p->next;
p->next=q->next;
delete q;
}
}
int main(){
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
for(int i=0;i<P;++i)
hash[i] = NULL;
int nrop,x,op;
scanf("%d",&nrop);
for( ; nrop ; --nrop){
scanf("%d%d",&op,&x);
switch(op){
case 1:Adauga(x); break;
case 2:Sterge(x); break;
case 3:printf("%d\n",Apartine(x)); break;
}
}
return 0;
}