Pagini recente » Cod sursa (job #557532) | Cod sursa (job #916524) | Cod sursa (job #2277890) | Cod sursa (job #1787092) | Cod sursa (job #735084)
Cod sursa(job #735084)
#include <cstdio>
#define MOD 66013
struct list{int x; struct list*next; }*h[MOD];
int m;
void insert(int x){
int p=x%MOD;
if(h[p]==NULL){
h[p]=new list; h[p]->x=x; h[p]->next=NULL; return; }
list*c=new list; c->x=x; c->next=h[p];
h[p]=c;
}
void erase(int x){
int p=x%MOD;
list*s,*u;
s=h[p];
if(s!=NULL){
if(s->x==x){ h[p]=h[p]->next; delete s; return; }
s=s->next;
while(s!=NULL){
u=s;
if(s->x==x){
if(s->next==NULL){ u->next=NULL; delete s; return; } else {
u->next=s->next; delete s; return; } }
s=s->next; } }
}
bool exist(int x){
int p=x%MOD;
list*s;
s=h[p];
while(s!=NULL){
if(s->x==x)return true;
s=s->next;}
return 0;
}
int main(){
int c,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&m);
for(int i=1;i<=m;i++){
scanf("%d %d",&c,&x);
switch(c){
case 1: insert(x); break;
case 2: erase(x); break;
case 3: printf("%d\n",exist(x)); }
}
}