Cod sursa(job #251664)

Utilizator BaduBadu Badu Badu Data 3 februarie 2009 01:01:03
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include<stdio.h>
#define MOD 667766
struct nod{
	long x;
	nod* urm;
};
nod* L[MOD-1];
long n;

void add(nod*&p,int nr){
	nod*q=new nod;
	q->urm=p;
	q->x=nr;
	p=q;
}
void del(nod*&p, int nr){
	nod*q=new nod;
	nod*z=new nod;
	q=p;
	if(!p)return;
	if(p->x==nr){p=p->urm;delete q;return;}
	for(;q->urm->x!=nr && q->urm;q=q->urm);
	z=q->urm;
	q->urm=z->urm;
	delete z;
}    
int vrf(nod*p, int nr){
	for(;p;p=p->urm) if(p->x==nr){printf("%d\n",1);return 1;}
	printf("%d\n",0);return 0;
}    
int main(){int o,nr,y;
	freopen("hashuri.in","rt",stdin);
	freopen("hashuri.out","wt",stdout);
	scanf("%ld",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&o,&nr);y=nr%MOD;
		if(o==1) {add(L[y],nr);continue;}
		if(o==2) {del(L[y],nr);continue;}
		if(o==3) {vrf(L[y],nr);continue;}
	}
	return 0;
}