Pagini recente » Cod sursa (job #3178428) | Cod sursa (job #317826) | Cod sursa (job #430724) | Cod sursa (job #227410) | Cod sursa (job #496532)
Cod sursa(job #496532)
#include<stdio.h>
#include<stdlib.h>
struct point{
int inf;
point *leg;
};
int tt,i,c,cc,n;
point *t,*a[1000002],*q;
void inserare(int x){
int nr;
nr=x%666013;
q=a[nr];
while (q && q->inf!=x) q=q->leg;
if (!q){
t=new point;
t->inf=x;
t->leg=a[nr];
a[nr]=t;
}
}
void sterge(int x){
int nr2;
point *qq;
nr2=x%666013;
q=a[nr2];
if (q==NULL) return;
else if (q->inf==x) {
a[nr2]=a[nr2]->leg;
delete(q);
}
else{
while (q &&q->inf!=x) q=q->leg;
if (q!=NULL){
qq=q->leg;
q=q->leg;
delete(qq);
}
}
}
int cautare(int x){
int nr3;
nr3=x%666013;
q=a[nr3];
bool ok=false;
while (q!=NULL){
if (q->inf==x) {
ok=true;
return(1);
}
}
if (ok==false) return(0);
}
int main(){
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for (i=0; i<=666013; i++) a[i]=NULL;
for (i=1; i<=n; i++){
scanf("%d%d",&c,&cc);
if (c==1){
if (cautare(cc)==0)
inserare(cc);
}
else if (c==2){
sterge(cc);
}
else if (c==3) {
tt=cautare(cc);
printf("%d\n",tt);
}
}
return(0);
}