Pagini recente » Cod sursa (job #1177325) | Cod sursa (job #2744528) | Cod sursa (job #1850) | Cod sursa (job #2491460) | Cod sursa (job #1090871)
//Include
#include <stdio.h>
#include <vector>
using namespace std;
FILE *in, *out;
//Constante
const int mod = 666013;
//Definitii
#define pb push_back
//Functii
void insertHash(int x);
void deleteHash(int x);
int checkHash(int x);
//Variabile
int num, type, value;
vector<int> hash[mod];
//Main
int main()
{
in = fopen("hash.in", "rt");
out = fopen("hash.out", "wt");
fscanf(in,"%d", &num);
while(num--)
{
fscanf(in,"%d%d", &type, &value);
if(type==1)
insertHash(value);
else if(type==2)
deleteHash(value);
else fprintf(out,"%d\n", checkHash(value));
}
fclose(in);
fclose(out);
return 0;
}
void insertHash(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it = hash[pos].begin(); it!=end; ++it)
if(*it==x)
return;
hash[pos].pb(x);
}
void deleteHash(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it = hash[pos].begin(); it!=end; ++it)
if(*it==x)
{
hash[pos].erase(it);
return;
}
}
int checkHash(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it = hash[pos].begin(); it!=end; ++it)
if(*it==x)
return 1;
return 0;
}