Cod sursa(job #377891)

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

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

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

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

void sterg(int key)
{
	int rest=key%p,i,pozitie;
	pozitie=caut(key);
	if(pozitie)
		for(i=pozitie;i<cont[rest];i++)
			h[rest][i]=h[rest][i+1];
	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;
}