Cod sursa(job #1481464)

Utilizator bogdanciurezubogdan ciurezu bogdanciurezu Data 4 septembrie 2015 16:04:59
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

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

typedef unsigned int tip;
const tip mod = 1365011, pHas = 661;
tip N;
vector <tip> Vec[mod];


int hash(int a){

	return ( (a * pHas) % mod );
}

void inserare(tip x){
	Vec[ hash(x) ].push_back(x);
}

void stergere(tip x){
	tip pozitie = hash(x);

	for( int i = 0; i < Vec[pozitie].size(); ++i )
		if( Vec[pozitie][i] == x)
			Vec[pozitie].erase( Vec[pozitie].begin() + i);
}

bool cautare(tip x){
	tip pozitie = hash(x);
	for( int i = 0; i < Vec[pozitie].size(); ++i )
		if( Vec[pozitie][i] == x )
			return 1;
	return 0;
}

int main(){
	tip x, val;
	f>>N;
	for(tip i = 1; i <= N; ++i){
		f>>val>>x;

		switch(val){
			case 1:inserare(x); break;
			case 2:stergere(x); break;
			case 3:g<<cautare(x)<<'\n'; break;
		}

	}
	return 0;
}