Cod sursa(job #626850)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 28 octombrie 2011 14:26:30
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <cstdio>


#define file_in "hashuri.in"
#define file_out "hashuri.out"

#define mod 666013

struct nod{
	
	int val;
	nod * urm;
};

nod * H[mod*2+1];
int N,tip,x;

int find(nod *& p,int x){
	
	nod * c;
	c=p;
	
	while(c){
		if (x==c->val)
			return 1;
		c=c->urm;
	}
	
	return 0;
	
}


void add(nod *& p, int x){
	
	nod * c;
	c=new nod;
	
	c->val=x;
	c->urm=p;
	p=c;
}

void sterge(nod *& p,int x){
	
	nod * c;
	nod * a;
	c=p;
	
	while(c->val!=x) c=c->urm;
		
	if (c==p){
		a=p;
		p=p->urm;
		delete a;
	}
	else{
		a=c;
		c=c->urm;
		delete a;
	}
}
	



int main(){
	
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	
	scanf("%d", &N);
	
	while(N--){
		
		scanf("%d %d", &tip, &x);
		
		if (tip==1){
			if (!find(H[x%mod],x))
				add(H[x%mod],x);
		}
		else
	    if (tip==2){
			if (find(H[x%mod],x))
				sterge(H[x%mod],x);
		}
		else
			printf("%d\n", find(H[x%mod],x));
	}
	
	return 0;
	
}