Cod sursa(job #2212224)

Utilizator b10nd3Oana Mancu b10nd3 Data 13 iunie 2018 17:07:54
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include<fstream>
#include<iostream>
#include<vector>
using namespace std;

#define MOD 666013
vector<int> hash[MOD];

vector<int>::iterator findValue(long long x){
	int bucket=x%MOD;
	vector<int>::iterator it;
	for(it=hash[bucket].begin();it!=hash[bucket].end();it++)
	   if(*it==x) return it;
	return hash[bucket].end();   
}

void insert(long long x){
	if(findValue(x)==hash[x%MOD].end())
	    hash[x%MOD].push_back(x);
}

void erase(long long x){
	vector<int>::iterator it=findValue(x);
	if(it!=hash[x%MOD].end())
	   hash[x%MOD].erase(it);
}

int main(){
	ifstream in("hashuri.in");
	FILE *out=fopen("hashuri.out","w");
	int n; in>>n;
	long long x; 
	short int op;
	while(n--){
	    in>>op>>x;
		if(op==1) insert(x);
		if(op==2) erase(x);
    	if(op==3) fprintf(out,"%i\n", findValue(x)!=hash[x%MOD].end() );
	}
	fclose(out); in.close();
	return 0;
}