Pagini recente » Cod sursa (job #155994) | Cod sursa (job #2932756) | Cod sursa (job #258638) | Cod sursa (job #2382544) | Cod sursa (job #2649689)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int modulo = 1000000;
vector<int> hashtable[1000000];
void add(int x) {
int key = x % modulo;
int c = 0;
for (int j = 0; j < hashtable[key].size(); ++j) {
if (x != hashtable[key][j]) {
c += 0;
} else {
c += 1;
}
}
if (c == 0) {
hashtable[key].push_back(x);
}
}
void deleteValue(int x) {
int key = x % modulo;
for (int j = 0; j < hashtable[key].size(); ++j) {
if (x == hashtable[key][j]) {
swap(hashtable[key][j], hashtable[key].back());
hashtable[key].pop_back();
}
}
}
int returnValue(int x) {
int key = x % modulo;
int answer = 0;
for (int j = 0; j < hashtable[key].size(); ++j) {
if (x == hashtable[key][j]) {
answer = 1;
return answer;
break;
} else {
answer = 0;
}
}
return answer;
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n;
fin >> n;
for (int i = 0; i <= n - 1; ++i) {
int op, x;
fin >> op >> x;
if (op == 1) {
add(x);
}
if (op == 2) {
deleteValue(x);
}
if (op == 3) {
fout << returnValue(x);
fout << "\n";
}
}
return 0;
}