Pagini recente » Cod sursa (job #2336313) | Cod sursa (job #190145) | Cod sursa (job #1811377) | Cod sursa (job #1806119) | Cod sursa (job #2134759)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
const int mod = 643847;
vector<int>vect[mod];
int Hash(int param) {
int base10 = 0;
while (param) {
base10 = (base10 * 97 + param % 10) % mod;
param /= 10;
}
return base10;
}
int Find(int x) {
int h = Hash(x);
for (int i = 0; i < vect[h].size(); i++) {
if (vect[h][i] == x) {
return i;
}
}
return -1;
}
void Insert(int x) {
int h = Hash(x);
if (Find(x) == -1)
vect[h].push_back(x);
}
void Del(int x) {
int h = Hash(x);
int pozX = Find(x);
if (pozX != -1) {
int lastpoz = vect[h].size()-1;
swap(vect[h][lastpoz], vect[h][pozX]);
vect[h].pop_back();
}
}
int main(){
int n, op, x;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> op >> x;
if (op == 1)Insert(x);
else if (op == 2)Del(x);
else cout << (bool)(Find(x) + 1) << "\n";
}
return 0;
}