Pagini recente » Cod sursa (job #431241) | Cod sursa (job #2114459) | Cod sursa (job #1038360) | Cod sursa (job #125213) | Cod sursa (job #1112353)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
class Hash {
public:
Hash() {}
void Insert(const int value) {
if (!Find(value))
table[GetKey(value)].push_back(value);
}
bool Find(const int value) const {
int key = GetKey(value);
for (vector<int>::const_iterator v = table[key].begin(); v != table[key].end(); ++v)
if (*v == value)
return true;
return false;
}
void Erase(const int value) {
int key = GetKey(value);
for (vector<int>::iterator v = table[key].begin(); v != table[key].end(); ++v) {
if (*v == value) {
table[key].erase(v);
return;
}
}
}
private:
static const int U = 666013;
vector<int> table[U];
static int GetKey(const int value) {
return value % U;
}
};
int main() {
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
Hash hash;
int q;
cin >> q;
for (; q > 0; --q) {
int type, value;
cin >> type >> value;
if (type == 1)
hash.Insert(value);
else if (type == 2)
hash.Erase(value);
else if (type == 3)
cout << hash.Find(value) << "\n";
}
cin.close();
cout.close();
return 0;
}