Cod sursa(job #1503165)

Utilizator meriniucrMeriniuc Razvan- Dumitru meriniucr Data 15 octombrie 2015 17:47:49
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>

struct value {
	int val;
	value *next;
};

value* hash[98318];

value*	find(int a, int b)
{
	value* it;

	it = hash[b];
	while (it && it -> val != a)
		it = it -> next;
	return it;
}

int	main()
{
	std::ifstream mama("hashuri.in");
	std::ofstream tata("hashuri.out");

	int	n;
	int	a;
	int	op;
	int	b;
	value	*findReturn;

	mama >> n;
	for (int i = 0; i < n; i += 1)
	{
		mama >>	op >> a;
		b = a % 98317;
		findReturn = find(a, b);
		if (op == 1 && !findReturn)
		{
			value r;
			r.val = a;
			r.next = hash[b];
			hash[b] = &r;
		}
		else if (op == 2 && findReturn)
		{
			if (hash[b] == findReturn)
				hash[b] = findReturn -> next;
			else
			{
				value *s;
				s = hash[b];
				while (s -> next -> val != a)
					s = s -> next;
				s -> next = s -> next -> next;
			}
		}
		else if (op == 3)
		{
			if (findReturn)
				tata << 1 << '\n';
			else
				tata << 0 << '\n';
		}
	}
	return 0;
}