Cod sursa(job #480415)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 27 august 2010 17:54:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <fstream>
#include <list>
#define hash 699967

using namespace std;

int N;

list<int>L[hash];


int cauta(int h,int x)
{
	if(!L[h].empty())
	{	
		for(list<int>::iterator i=L[h].begin();i!=L[h].end();i++)
		{
			if (*i==x) return 1;
		}
		return 0;
	}
	else return 0;
}

inline int h(int x)
{
	return x%hash;
}

void citire()
{
	fstream fin("hashuri.in",ios::in);
	fstream fout("hashuri.out",ios::out);
	fin>>N;
	int a,x,z;
	for(register int i=1;i<=N;i++)
	{
		fin>>a>>x;
		switch(a)
		{
		case(1):
			{
				z=h(x);
				if(!cauta(z,x)) L[z].push_back(x);
				break;
			}
		case(2):
			{
				z=h(x);
					list<int>::iterator itr=L[z].begin();
					while(itr!=L[z].end() && *itr!=x)
						itr++;
					if(*itr==x)
						L[z].erase(itr);
				break;
			}
		case(3):
			{
				z=h(x);
				if(cauta(z,x)) 
					fout<<"1\n";
				else 
					fout<<"0\n";
				break;
			}
		}
	}
	
	fin.close();
	fout.close();
}


int main(int argc,char* argv[])
{
	citire();

}