Pagini recente » Cod sursa (job #1202140) | Cod sursa (job #312764) | Cod sursa (job #257980) | Cod sursa (job #200382) | Cod sursa (job #714630)
Cod sursa(job #714630)
#include <cstdio>
#define file_in "hashuri.in"
#define file_out "hashuri.out"
#define mod (666013)
class nod{
public:
int val;
nod * urm;
};
class Hash{
private:
nod * H[mod+20];
public:
//Hash();
int cauta(int x);
void adauga(int x);
void sterge(int x);
//~Hash();
};
Hash h;
int Q,Tip,x;
int Hash::cauta(int x){
nod * p=H[x%mod];
nod * c=p;
while(c){
if (c->val==x)
return 1;
c=c->urm;
}
return 0;
}
void Hash::adauga(int x){
nod * p=H[x%mod];
nod * c;
c=new nod;
c->val=x;
c->urm=p;
p=c;
}
void Hash::sterge(int x){
nod * p=H[x%mod];
nod * c;
nod * a;
c=p;
while(c->val!=x) c=c->urm;
if (c==p){
a=p;
p=p->urm;
delete a;
}
else{
a=c;
c=c->urm;
delete a;
}
}
//Hash::~Hash(){}
int main(){
freopen(file_in,"r",stdin);
freopen(file_out,"w",stdout);
scanf("%d", &Q);
while(Q--){
scanf("%d %d", &Tip, &x);
if (Tip==1){
if (!h.cauta(x))
h.adauga(x);
}
else
if (Tip==2){
if (h.cauta(x))
h.sterge(x);
}
else{
printf("%d\n", h.cauta(x));
}
}
return 0;
}