Cod sursa(job #1427091)

Utilizator aciobanusebiCiobanu Sebastian aciobanusebi Data 1 mai 2015 15:17:25
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include<iostream>
#include<fstream>
#define PRIME 402653189
#define h(x) ((x) % PRIME)
using namespace std;

struct nod
{
	int info;
	nod *urm;
};

struct List
{
	nod* prim;
};
List T[PRIME];
int main()
{
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	int op, x, n;
	f >> n;
	for(int i=1;i<=n;i++)
	{
		f >> op;
		f >> x;
		switch (op)
		{
		case 1:
			if (T[h(x)].prim == NULL)
			{
				T[h(x)].prim = new nod;
				T[h(x)].prim->info = x;
				T[h(x)].prim->urm = NULL;
			}
			break;
		case 2:
			if (T[h(x)].prim != NULL)
			{
				nod *p = T[h(x)].prim;
				nod *prec=NULL;
				while (x != p->info)
				{
					prec = p;
					p = p->urm;
				}
				if (prec==NULL)
				{
					delete T[h(x)].prim;
					T[h(x)].prim = NULL;
				}
				else
				{
					prec->urm = p->urm;
					delete p;
				}
			}
			break;
		case 3:
			if (T[h(x)].prim == NULL)
				g << 0 << '\n';
			else g << 1 << '\n';
			break;
		}
	}
	f.close();
	g.close();

	int i;
	cin >> i;
	return 0;
}