Cod sursa(job #2738986)

Utilizator nusmaibunkeleviprofesor cicalescu nusmaibunkelevi Data 6 aprilie 2021 17:26:49
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 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]) nn->next=v[r];
	
v[r]=nn;
	
}
	
 
	
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;
	
}