Cod sursa(job #957279)

Utilizator superman_01Avramescu Cristian superman_01 Data 4 iunie 2013 18:58:22
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include<cstdio>
#include<vector>

#define MOD 660013

FILE *f=fopen("hashuri.in","r");
FILE *g=fopen("hashuri.out","w");

using namespace std;

vector<int> HASH[MOD];
int tests;
int type,x;

vector<int>::iterator Find( int value )
{
	int key;
	key=x%MOD;
	for(vector<int>::iterator it = HASH[key].begin() ;  it != HASH[key].end() ; ++it )
		if( *it == value)
			return it;
    return HASH[key].end();
}
void Add  ( int value )
{
	int key;
	key=x%MOD;
    if( Find(value) == HASH[key].end() )
      HASH[key].push_back(value);	   
}
void Del ( int value )
{
	vector <int> ::iterator it;
	int key;
	key=x%MOD;
	it=Find(x);
	if( it != HASH[key].end() )
	HASH[key].erase(it);	
}
void Read( void )
{
	fscanf(f,"%d",&tests);
	for(;tests;--tests)
	{
		fscanf(f,"%d%d",&type,&x);
		if( type == 1 )
			{
				Add(x);
				continue;
		}
		if( type == 2 )
		{
			Del(x);
			continue;
		}
		if( type == 3 )
		{
			fprintf(g,"%d\n",Find(x)!=HASH[x%MOD].end());
		}			
	}
}

int main ( void )
{
	Read();
	return 0;
}