Pagini recente » Cod sursa (job #1001163) | Cod sursa (job #1732060) | Cod sursa (job #1854263) | Cod sursa (job #1911728) | Cod sursa (job #1354547)
#include<stdio.h>
#include<vector>
using namespace std;
FILE *in, *out;
//definitions
#define pb push_back
//constants
const int modulo = 666013;
//variables
int oper;
int type, value;
vector<int> Hash[modulo];
//functions
void insert(int value);
void erase(int value);
int search(int value);
int main(void)
{
in = fopen("hashuri.in", "rt");
out = fopen("hashuri.out", "wt");
fscanf(in, "%d", &oper);
while(oper--)
{
fscanf(in, "%d", &type);
fscanf(in, "%d", &value);
if(type == 1)
insert(value);
else
if(type == 2)
erase(value);
else
fprintf(out, "%d\n", search(value));
}
fclose(in);
fclose(in);
return 0;
}
void insert(int value)
{
int pos = value % modulo;
vector<int> :: iterator it, end=Hash[pos].end();
for(it=Hash[pos].begin(); it!=end; ++it)
if( *it == value)
return;
Hash[pos].pb(value);
}
void erase(int value)
{
int pos = value % modulo;
vector<int> :: iterator it, end=Hash[pos].end();
for( it=Hash[pos].begin(); it!=end; ++it)
if( *it == value)
{
Hash[pos].erase(it);
return;
}
}
int search(int value)
{
int pos = value % modulo;
vector<int> :: iterator it, end=Hash[pos].end();
for( it=Hash[pos].begin(); it!=end; ++it)
if( *it == value)
return 1;
return 0;
}