Cod sursa(job #371354)

Utilizator nusmaibunkeleviprofesor cicalescu nusmaibunkelevi Data 4 decembrie 2009 23:23:55
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include<stdio.h>
#include<stdlib.h>

#define NN 999983
#define NM 1000001
struct nod{
	int x;
	nod*next;
	};

int n;
nod* v[NM];

void add(int r,int x){
nod *nn=new nod;
nn->x=x;
if(!v[r]) v[r]=nn;
else nn->next=v[r];
}

int cauta(int x){
int r=x%NN;
nod *nc=v[r];
while(nc&&nc->x!=x) nc=nc->next;
return nc!=NULL;
}

void sterge(int x){
int r=x%NN;
nod *nc=v[r];
if(!nc) return;
while(nc&&nc->x!=x) nc=nc->next;
if(nc) nc->x=0;
}

int main(){
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int i,m,op,x;
char s[15],*p;
scanf("%d\n",&m);
while(m--){
	fgets(s,14,stdin);
	p=s;
	op=atoi(p);p+=2;x=atoi(p);
	switch(op){
		case 1:i=cauta(x);
			   if(!i) add(x%NN,x);
			   break;
		case 2:sterge(x);break;
		case 3:i=cauta(x);
			   if(i) printf("1\n");
			   else printf("0\n");
		}
	}
return 0;
}