Pagini recente » Cod sursa (job #1122470) | Cod sursa (job #2936733) | Cod sursa (job #2465071) | Cod sursa (job #540844) | Cod sursa (job #1256016)
#include <iostream>
#include <fstream>
#include <vector>
const int MOD = 666013;
class Hash {
private:
std::vector<int> a[MOD];
public:
Hash() {
}
void insert(int x) {
int i = x % MOD;
bool ok = false;
for (int j = 0; j < a[i].size(); j++) {
if (a[i][j] == x) {
ok = true;
break;
}
}
if (ok == false) {
a[i].push_back(x);
}
}
void erase(int x) {
int i = x % MOD;
for (int j = 0; j < a[i].size(); j++) {
if (a[i][j] == x) {
a[i].erase(a[i].begin() + j);
break;
}
}
}
bool has(int x) {
int i = x % MOD;
for (int j = 0; j < a[i].size(); j++) {
if (a[i][j] == x) {
return true;
}
}
return false;
}
};
std::ifstream f("hashuri.in");
std::ofstream g("hashuri.out");
Hash hash;
int main()
{
int n;
f >> n;
for (int i = 1; i <= n; i++) {
int op, x;
f >> op >> x;
if (op == 1) hash.insert(x);
if (op == 2) hash.erase(x);
if (op == 3) g << hash.has(x) << '\n';
}
f.close();
g.close();
return 0;
}