Cod sursa(job #323372)

Utilizator bog29Antohi Bogdan bog29 Data 11 iunie 2009 22:30:05
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include<fstream>
#define dmax 500
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n,hash[200][dmax],op,x,it[201];
int fh(int x)
{	return x%201;
}
void add()
{	it[fh(x)]++;
	hash[fh(x)][it[fh(x)]]=x;
}
void remove()
{	int i,j;
	for(i=1;i<=it[fh(x)];i++)
		if(hash[fh(x)][i]==x)
		{	for(j=i;j<it[fh(x)];j++)
				hash[fh(x)][j]=hash[fh(x)][j+1];
			it[fh(x)]--;
		}
}
int search()
{	int i;
	for(i=1;i<=it[fh(x)];i++)
		if(hash[fh(x)][i]==x)return 1;
	return 0;
}
int main()
{	int i;
	in>>n;
	for(i=1;i<=n;i++)
	{	in>>op>>x;
		if(op==1)add();
		if(op==2)remove();
		if(op==3)out<<search()<<'\n';
	}
	in.close();
	out.close();
	return 0;
}