Pagini recente » Cod sursa (job #1665622) | Cod sursa (job #1186948) | Cod sursa (job #228313) | Cod sursa (job #2083846) | Cod sursa (job #238907)
Cod sursa(job #238907)
#include<stdio.h>
#define maxh 666013
struct nod{int inf;nod *urm;} *h[maxh+2];
int i,n,t,x;
FILE *g=fopen("hashuri.out","w");
void add(nod *&p,int x){
nod *q;
for(q=p;q!=NULL && p->inf != x ;q=q->urm);
if(q!=NULL) return ;
nod *t=new nod;
t->inf=x;
t->urm=p;
p=t;
}
void find(nod *&p,int x){
nod *q;
for(q=p;q!=NULL && p->inf != x ;q=q->urm);
if(q!=NULL) {
fprintf(g,"1\n");
return;}
fprintf(g,"0\n");
}
void erase(nod *&p,int x){
nod *q,*w;
for(q=p;q!=NULL && p->inf != x ;q=q->urm);
if(q == NULL) return;
if(q == p){
w=p;
p=p->urm;
delete w;
}
else{
w=q;
q=q->urm;
delete w;
}
}
int main(){
FILE *f=fopen("hashuri.in","r");
fscanf(f,"%d",&n);
for(i=1;i<=n;i++){
fscanf(f,"%d %d",&t,&x);
if(t==1) add(h[x%maxh],x);
if(t==2) erase(h[x%maxh],x);
if(t==3) find(h[x%maxh],x);
}
fclose(f);
fclose(g);
return 0;
}