Cod sursa(job #348366)

Utilizator serbanlupulupulescu serban serbanlupu Data 15 septembrie 2009 16:51:52
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

#define PRIM 666203

vector<int > H[PRIM];

int check(int temp)
{
	vector<int >::iterator it;

	for (it=H[temp%PRIM].begin(); it<H[temp%PRIM].end(); it++)
		if (*it == temp)
			return 1;
	return 0;
}

void del(int temp)
{
	for (int i=0; i<=H[temp%PRIM].size()-1; ++i)
	{
		if (H[temp%PRIM][i]==temp)
		{
			swap(H[temp%PRIM][i], H[temp%PRIM][H[temp%PRIM].size()-1]);
			H[temp%PRIM].pop_back();
			break;
		}
	}
}

void solve()
{
	fstream f("test.in", ios::in);
	fstream g("test.out", ios::out);

	int n;
	int aux;
	int temp;

	f>>n;

	for (int i=1; i<=n; ++i)
	{
		f>>aux;
		if (aux == 1)
		{
			f>>temp;
			if (check(temp) == 0)
				H[temp%PRIM].push_back(temp);
		}
		if (aux == 2)
		{
			f>>temp;
			if (check(temp))
				del(temp);
		}
		if (aux == 3)
		{
			f>>temp;
			g<<check(temp)<<"\n";
		}
	}
	f.close();
	g.close();
}

int main()
{
	solve();
	return 0;
}