Pagini recente » Cod sursa (job #3130410) | Cod sursa (job #960122) | Cod sursa (job #135759) | Cod sursa (job #571777) | Cod sursa (job #1090879)
//Include
#include <stdio.h>
#include <vector>
using namespace std;
FILE *in, *out;
//Constante
const int mod = 666013;
//Definitii
#define pb push_back
//Functii
void insertHa(int x);
void deleteHa(int x);
int checkHa(int x);
//Variabile
int num, type, value;
vector<int> hashi[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)
insertHa(value);
else if(type==2)
deleteHa(value);
else fprintf(out,"%d\n", checkHa(value));
}
fclose(in);
fclose(out);
return 0;
}
void insertHa(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hashi[pos].end();
for(it = hashi[pos].begin(); it!=end; ++it)
if(*it==x)
return;
hashi[pos].pb(x);
}
void deleteHa(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hashi[pos].end();
for(it = hashi[pos].begin(); it!=end; ++it)
if(*it==x)
{
hashi[pos].erase(it);
return;
}
}
int checkHa(int x)
{
int pos = x % mod;
vector<int>::iterator it, end = hashi[pos].end();
for(it = hashi[pos].begin(); it!=end; ++it)
if(*it==x)
return 1;
return 0;
}