Cod sursa(job #1382809)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 9 martie 2015 16:29:34
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>
#define MOD 666013

using namespace std;

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

int n, op, val;
vector < int > H[MOD];

void hInsert(int val)
{

	int hKey = val % MOD;

	for (vector<int>::iterator it = H[hKey].begin(); it != H[hKey].end(); it++)
		if (*it == val)
			return;

	H[hKey].push_back(val);

}

void hDelete(int val)
{

	int hKey = val % MOD;

	for (vector<int>::iterator it = H[hKey].begin(); it != H[hKey].end(); it++) {
		if (*it == val) {
			H[hKey].erase(it);
			return;
		}
	}
}

bool hFind(int val)
{

	int hKey = val % MOD;

	for (vector<int>::iterator it = H[hKey].begin(); it != H[hKey].end(); it++)
		if (*it == val)
			return true;

	return false;
}

int main()
{
	f >> n;

	for (int i = 1; i <= n; i++) {
		f >> op >> val;
		if (op == 1)
			hInsert(val);
		else if (op == 2)
			hDelete(val);
		else
			g << hFind(val) << "\n";
	}

	return 0;
}