Pagini recente » Cod sursa (job #1371576) | Cod sursa (job #662263) | Cod sursa (job #2049513) | Cod sursa (job #1484819) | Cod sursa (job #822819)
Cod sursa(job #822819)
// Include
#include <fstream>
#include <vector>
using namespace std;
// Definitii
#define pb push_back
// Constante
const int mod = 666013;
// Functii
void hashInsert(int val);
void hashDelete(int val);
bool hashCheck(int val);
// Variabile
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int num;
int type, value;
vector<int> hash[mod];
// Main
int main()
{
in >> num;
while(num--)
{
in >> type >> value;
if(type == 1)
hashInsert(value);
else if(type == 2)
hashDelete(value);
else
out << (hashCheck(value)? 1 : 0) << '\n';
}
in.close();
out.close();
return 0;
}
void hashInsert(int val)
{
int pos = val % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it=hash[pos].begin() ; it!=end ; ++it)
if(*it == val)
return;
hash[pos].pb(val);
}
void hashDelete(int val)
{
int pos = val % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it=hash[pos].begin() ; it!=end ; ++it)
if(*it == val)
{
hash[pos].erase(it);
return;
}
}
bool hashCheck(int val)
{
int pos = val % mod;
vector<int>::iterator it, end = hash[pos].end();
for(it=hash[pos].begin() ; it!=end ; ++it)
if(*it == val)
return true;
return false;
}