Cod sursa(job #644253)

Utilizator an_drey_curentandreycurent an_drey_curent Data 5 decembrie 2011 22:20:52
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include<iostream>
#include<vector>
#include<fstream>
#define prim 123457
using namespace std;
vector<long int>v[123460];
ifstream f("hash.in");
ofstream g("hash.out");
int existenta(long int x,long int cheia)
{
	long int i;
	for(i=0;i<v[cheia].size();i++)
		if(v[cheia][i]==x)
			return i;
	return -1;
}
void inserare(long int x,long int cheia)
{
	if(existenta(x,cheia)==-1)
		v[cheia].push_back(x);
}
void stergere(long int x,long int cheia)
{
	long int i,poz;
	poz=existenta(x,cheia);
	if(poz!=-1)
	{
		v[cheia][poz]=v[cheia][v[cheia].size()-1];
		v[cheia].pop_back();
	}
}
void citire()
{
	long int i,N,instructiune,numar,cheia;
	f>>N;
	for(i=1;i<=N;i++)
	{
		f>>instructiune;
		f>>numar;
		cheia=numar%prim;
		if(instructiune==1)
			inserare(numar,cheia);
		else
			if(instructiune==2)
				stergere(numar,cheia);
			else
				if(instructiune==3)
					if(existenta(numar,cheia)==-1)
						g<<0<<endl;
					else
						g<<1<<endl;
	}
}
int main()
{
	citire();
	f.close();
	g.close();
	return 0;
}