Cod sursa(job #629379)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 3 noiembrie 2011 11:21:08
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
#define p 666013
using namespace std;
vector<int> h[p];
void adauga(long x)
{
	vector<int>::iterator it=h[x%p].begin();
	while ((it!=h[x%p].end())&&((*it)!=x))
		it++;
	if ((it==h[x%p].end())||(*it)!=x)
		h[x%p].push_back(x);
}//adauga

void sterge(long x)
{
	unsigned long i=0;
	while ((i<h[x%p].size())&&(h[x%p][i]!=x))
		i++;
	if ((i<h[x%p].size())&&(h[x%p][i]==x))
	{
		h[x%p][i]=h[x%p][h[x%p].size()];
		h[x%p].pop_back();
	}//if
}//sterge

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

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)<<"\n";
	}//for i
   return 0;
}//main