Pagini recente » Cod sursa (job #1879912) | Cod sursa (job #2124274) | Cod sursa (job #1362022) | Cod sursa (job #673690) | Cod sursa (job #3277805)
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int MOD = 666103;
const int BASE = 31;
int hashBaza31(int x) {
long long hash_value = 0;
string key = to_string(x);
for (char ch : key) {
hash_value = (hash_value * BASE + ch) % MOD;
}
return (int)hash_value;
}
int main()
{
int n;
in >> n;
vector<list<int>> hash_table(MOD);
while(n--){
int op, x;
in >> op >> x;
int hash_value = hashBaza31(x);
if(op == 1){
hash_table[hash_value].push_back(x);
}
if(op == 2){
auto &bucket = hash_table[hash_value];
auto it = find(bucket.begin(), bucket.end(), x);
if(it != bucket.end()) {
bucket.erase(it);
}
}
if(op == 3){
auto &bucket = hash_table[hash_value];
bool found = find(bucket.begin(), bucket.end(), x) != bucket.end();
out << (found ? 1 : 0) << '\n';
}
}
return 0;
}