Cod sursa(job #633465)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 13 noiembrie 2011 20:20:51
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#include <vector>
#define p 666013
using namespace std;
vector<int> h[p];

vector<int>::iterator cauta(long x)
{
	vector<int>::iterator it;
	for (it=h[x%p].begin(); it!=h[x%p].end(); it++)
		if (*it==x)
			return it;
	return h[x%p].end();
}//cauta

void adauga(long x)
{
	if (cauta(x)==h[x%p].end())
		h[x%p].push_back(x);
}//adauga

void sterge(long x)
{
	vector<int>::iterator it=cauta(x);
	if (it!=h[x%p].end())
		h[x%p].erase(it);
}//sterge

int main()
{
	long n, o, x;
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	fin>>n;
	for (long i=0; i<n; i++)
	{
		fin>>o>>x;
		if (o==1)
			adauga(x);
		if (o==2)
			sterge(x);
		if (o==3)
			fout<<(cauta(x)!=h[x%p].end())<<"\n";
	}//for i
   return 0;
}//main