Cod sursa(job #629351)

Utilizator andreea29Iorga Andreea andreea29 Data 3 noiembrie 2011 10:34:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include<fstream>
#include<vector>

using namespace std;
#define hash 666013
int n, x;
vector <int> vhash[hash];

inline void add (int x)
{
	int y, i, l;
	y=x%hash;
	l=vhash[y].size();

	for (i=0; i<l; i++)
		if (vhash[y][i]==x) return;

	vhash[y].push_back(x);
}

inline void remove (int x)
{
	int y, i, l;
	y=x%hash;
	l=vhash[y].size();

	for (i=0; i<l; i++)
		if (vhash[y][i] == x)
		{
			vhash[y][i] = vhash[y][l-1];
			vhash[y].pop_back();
			return;
		}
}

int irina_ma_enerveaza (int x)
{
	int y, i, l;
	y=x%hash;
	l=vhash[y].size();
	
	for (i=0; i<l; i++)
		if (vhash[y][i]==x) return 1;

	return 0;
}

int main()
{
	int op, el, i;
	ifstream f("hashuri.in");
	ofstream h("hashuri.out");
	f>>n;
	for (i=1; i<=n; i++)
	{
		f>>op;
		f>>el;
		if (op==1)
			add(el);
		if (op==2)
			remove(el);
		if (op==3)
			h<<irina_ma_enerveaza(el)<<'\n';
		
	}
	f.close();
	h.close();
	return 0;
}