Cod sursa(job #377910)

Utilizator GotenAmza Catalin Goten Data 26 decembrie 2009 20:59:58
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include<fstream.h>

int p=666667,h[666668][50],cont[666668];

int caut(int key)
{
	int rest=key%p,i,pozitie=0;
	for(i=1;i<=cont[rest]&&!pozitie;i++)
		if(h[rest][i]==key)
			pozitie=i;
	return pozitie;
}

void adaug(int key)
{
	int rest=key%p;
	if(!caut(key))
	{
		cont[rest]++;
		h[rest][cont[rest]]=key;
	}
}

void sterg(int key)
{
	int rest=key%p,pozitie;
	pozitie=caut(key);
	if(pozitie)
		h[rest][pozitie]=h[rest][cont[rest]];
	cont[rest]--;	
}



int main()
{
	int i,n,op,x;
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	f>>n;
	for(i=1;i<=n;i++)
	{
		f>>op>>x;
		if(op==1)
			adaug(x);
		else
			if(op==2)
				sterg(x);
			else 
				if(caut(x))
					g<<"1\n";
				else
					g<<"0\n";
	}
	return 0;
}