Cod sursa(job #675439)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 7 februarie 2012 16:55:06
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>
#include <list>
using namespace std;

ifstream fi ("hashuri.in");
ofstream fo ("hashuri.out");

const int mod = 882377;
list <int> H[mod+5];
list <int> :: iterator p;

void cauta (int x, int h)
{
	for (p = H[h].begin(); p != H[h].end(); p++)
		if (*p == x)
			return;
	p = NULL;
}

int main ()
{
	int t, x, n, h;
	
	fi >> n;
	while ( n-- )
	{
		fi >> t >> x;
		h = x % mod;
		if (t == 1)
		{
			cauta (x, h);
			if (p == NULL)
				H[h].push_back (x); 
		}
		else if (t == 2)
		{
			cauta (x, h);
			if (p != NULL)
				H[h].erase (p);
		}
		else if (t == 3)
		{
			cauta (x, h);
			fo << (p != NULL) << '\n';
		}
	}	
	
	return 0;
}