Cod sursa(job #1066921)

Utilizator IonMosnoiIon Mosnoi IonMosnoi Data 25 decembrie 2013 20:17:28
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include<fstream>
#include<algorithm>
using namespace std;

const int maxn = 1000;
const int M = 1000;
//typedef int arrr[maxn];
int hash1[maxn][maxn];
int nr[maxn];
  //std::vector < pair<int,int> > hash[maxn]; 

void adauga(int a){
	int x=a%M,y=a/M;
		for(int j=0;j<nr[x];j++){
		if(hash1[x][j] == a/M){		
		return;
			
		}
	}
	hash1[x][++nr[x]-1]=y;
}
void sterge(int a){
	int x=a%M; 
	for(int j=0;j<nr[x];j++){
		if(hash1[x][j]== a/M){
			swap(hash1[x][j],hash1[x][--nr[x]]);
			
			//hash[a%M][j]=-1;
			break;
		}
	}
}
int check(int a){
	int x=a%M;
		for(int j=0;j<nr[x];j++){
		if(hash1[x][j] == a/M){
		return 1;
			break;
		}
	}	
	return 0;
}
main(){
  ifstream fin("hashuri.in");
  ofstream fout("hashuri.out"); 
  
 int n,a,b;
 for(int i=0;i<M;nr[++i]=0);
  fin>>n;
  for(int i=1;i<=n;i++){
  	fin>>a>>b;
  	if(a==1){
  		adauga(b);
  	}else if(a==2){
  		sterge(b);
  	}else{
  		fout<<check(b)<<"\n";
  	}
  }
 
  
  
 
    fin.close(); fout.close();
  
}