Cod sursa(job #766314)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 10 iulie 2012 23:22:12
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>

using namespace std;

#define mod 666013

ifstream f("hashuri.in");
ofstream g("hashuri.out");

class Hash{
	
	int *H;
	int size;
	
public:
	
	Hash(int N){
		
		H=new int[N];
		size=N;
	}
	~Hash(){
		
		delete[] H;
	}
	void insert(int X);
	int search(int X);
	void erase(int X);
	
};

void Hash::insert(int X){
	
	int x=X%mod;
	this->H[x]=X;
}

int Hash::search(int X){
	
	for (int i=0;i<mod;++i)
		 if (this->H[i]==X)
			 return 1;
		 
	return  0;
}	

void Hash::erase(int X){
	
	for (int i=0;i<mod;++i)
		 if (this->H[i]==X){
			 this->H[i]=-1;
			 return ;
		 }
}


int main(){
	
	Hash Q(mod);
	
	int T,tip,X;
	
	f>>T;
	
	while(T--){
	
		f>>tip>>X;
		
		if (tip==1){
			if (!Q.search(X))
				Q.insert(X);
		}
		else
		if (tip==2){
			if (Q.search(X))
				Q.erase(X);
		}
		else
			g<<Q.search(X)<<"\n";
	}
	
	return 0;
}