Cod sursa(job #463914)

Utilizator darrenRares Buhai darren Data 17 iunie 2010 22:09:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include<fstream>
#include<list>
using namespace std;

const int MOD = 666013;

list<int> hash[MOD];

void add(int value)
{
	int pos = value % MOD;
	if (find(hash[pos].begin(), hash[pos].end(), value) == hash[pos].end())
		hash[pos].push_back(value);
}

void del(int value)
{
	int pos = value % MOD;
	if (find(hash[pos].begin(), hash[pos].end(), value) != hash[pos].end())
		hash[pos].erase(find(hash[pos].begin(), hash[pos].end(), value));
}

bool tell(int value)
{
	int pos = value % MOD;
	return (find(hash[pos].begin(), hash[pos].end(), value) != hash[pos].end()) ? 1 : 0;
}


int n;
int main()
{
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	
	fin >> n;
	while (n--)
	{
		int type, value;
		fin >> type >> value;
		switch (type)
		{
		case 1:
			add(value);
			break;
		case 2:
			del(value);
			break;
		case 3:
			fout << tell(value) << '\n';
		}
	}
}