Cod sursa(job #1692618)

Utilizator PetruZZatic Petru PetruZ Data 21 aprilie 2016 12:02:26
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
//#include <iostream>

using namespace std;

ifstream cin ("hashuri.in");
ofstream cout("hashuri.out");

int n;

typedef struct nod{
	int inf;
	nod* next;
}* lista;

const int m=666013;

lista a[m];

void insert(int x){
	int pz=x%m; 	 
	bool in=true;
	for(lista p=a[pz]; p&&in; p=p->next) if(p->inf==x)in=false;
	
	if(in) {
		lista u=new nod;
		u->inf=x;
		u->next=a[pz];
		a[pz]=u;
	}
}

void delet(int x){
    int pz=x%m; 	 
	for(lista p=a[pz],u=a[pz]; p; p=p->next) 
	{
	if(p->inf==x){
				  	if(p==a[pz])a[pz]=p->next;
				  	else if(p->next) {
				  		u->next=p->next;
					  }
 					  else u->next=NULL;
					}
	u=p;
	}
	
}

bool check(int x){
    int pz=x%m; 	 
	for(lista p=a[pz]; p; p=p->next) if(p->inf==x) return 1;
	return 0;
}

int main(){
	
	cin >> n;
	
	int x,o;
	for(int i=0; i<n; i++){
		cin >> o >> x;
		
		if(o==1) insert(x);
		if(o==2) delet(x);
		if(o==3) cout << check(x) << "\n";
		
	}
	
return 0;
}