Cod sursa(job #353184)

Utilizator andrei.sfrentSfrent Andrei andrei.sfrent Data 4 octombrie 2009 13:23:01
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>
#include <list>

using namespace std;

#define HASH 1000
ifstream fi("hashuri.in");
ofstream fo("hashuri.out");

list<int> tab[HASH];

int exista(int x)
{
	int listID = x % HASH;
	for(list<int>::iterator it = tab[listID].begin(); it != tab[listID].end(); ++it)
		if(*it == x) 
			return 1;
	return 0;
}

void adauga(int x)
{
	if(!exista(x)) tab[x % HASH].push_back(x);
}

void sterge(int x)
{
	//if(exista(x)) 
		tab[x % HASH].remove(x);
}

int main()
{
	int nop, opcode, val;
	fi >> nop;
	while(nop--)
	{
		fi >> opcode >> val;
		switch(opcode)
		{
			case 1:
				adauga(val);
				break;
			case 2:
				sterge(val);
				break;
			case 3:
				fo << exista(val) << "\n";
				break;
		}
	}	
	return 0;
}