Pagini recente » Cod sursa (job #1307777) | Profil ovidiu_moro | Cod sursa (job #2015868) | Cod sursa (job #1151640) | Cod sursa (job #2487345)
#include <iostream>
#include <vector>
#include <fstream>
#define MOD 600000
using namespace std;
vector<int> hashTable[MOD];
vector<int>::iterator findValue(int value) {
int poz = value % MOD;
vector<int>::iterator i;
for(i=hashTable[poz].begin(); i<hashTable[poz].end(); i++)
if(*i == value) return i;
return hashTable[poz].end();
}
void insertValue(int value) {
int poz = value % MOD;
if(findValue(value) == hashTable[poz].end())
hashTable[poz].push_back(value);
}
void eraseValue(int value) {
int poz = value % MOD;
vector<int>::iterator i = findValue(value);
if(i != hashTable[poz].end())
hashTable[poz].erase(i);
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N, op, value, index;
fin >> N;
for(int i=1; i<=N; i++) {
fin >> op >> value;
if(op == 1) {
insertValue(value);
}
else if(op == 2) {
eraseValue(value);
}
else {
if(findValue(value) != hashTable[value%MOD].end())
fout << 1 << '\n';
else fout << 0 << '\n';
}
}
return 0;
}