Pagini recente » Cod sursa (job #1280100) | Cod sursa (job #2259476) | Cod sursa (job #298910) | Cod sursa (job #630802) | Cod sursa (job #628299)
Cod sursa(job #628299)
#include <stdio.h>
#define MOD 76543
int n;
struct hash{
int x;
struct hash*next;}*p[MOD+1];
void add(int x,int y){
if(p[y]==NULL){p[y]=new hash; p[y]->x=-1; p[y]->next=NULL;};
hash*a=p[y];
while(a->x!=-1){
if(a->x==x)return;
a=a->next;}
a=new hash;
a->x=x;
a->next=p[y]; p[y]=a;
}
void del(int x,int y){
hash*a=p[y];
if(p[y]==NULL)return;
if(p[y]->x==x){p[y]=p[y]->next; return;}
while(a->x!=-1){
if(a->next->x==x){
a->next=a->next->next;
return;};
a=a->next;
}
}
bool exy(int x,int y){
hash*a=p[y];
if(p[y]==NULL)return 0;
while(a->x!=-1){
if(a->x==x)return 1;
a=a->next;};
return 0;
}
int main(){
int i,op,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d",&op,&x);
switch(op){
case 1:add(x,x%MOD);break;
case 2:del(x,x%MOD);break;
case 3:printf("%d\n",exy(x,x%MOD));
}
}
}