Pagini recente » Cod sursa (job #1140831) | Cod sursa (job #3294015) | Cod sursa (job #365094) | Cod sursa (job #383530) | Cod sursa (job #2295846)
#include<fstream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
int n,cod,x;
struct nod{
int val;
nod *urm;
} *Hash[735337];
nod* find_value(int x){
int index=x%735337;
for(nod *p=Hash[index];p;p=p->urm)
if(p->val==x) return p;
return NULL;
}
void insert_value(int x){
int index=x%735337;
if(!find_value(x)){
if(Hash[index]==NULL){
Hash[index]=new nod;
Hash[index]->val=x;
Hash[index]->urm=NULL;
}
else{
nod *p=new nod;
p->val=x;
p->urm=Hash[index];
Hash[index]=p;
}
}
}
void erase_value(int x){
int index=x%735337;
nod *adr=find_value(x);
if(adr){
if(adr==Hash[index]){
nod *p=Hash[index];
Hash[index]=Hash[index]->urm;
delete p;
}
else{
nod *p;
for(p=Hash[index];p->urm!=adr;p=p->urm);
p->urm=p->urm->urm;
delete adr;
}
}
}
int main(){
cin>>n;
while(n--){
cin>>cod>>x;
if(cod==1)
insert_value(x);
else if(cod==2)
erase_value(x);
else if(cod==3)cout<<(find_value(x)!=NULL)<<'\n';
}
}