Pagini recente » Cod sursa (job #2408775) | Cod sursa (job #1342607) | Cod sursa (job #2395711) | Cod sursa (job #2534160) | Cod sursa (job #2183811)
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#define HMAX 66013
using namespace std;
int mHash(int x) {
return x % HMAX;
}
int main()
{
ifstream in("hashuri.in");
ofstream out("hashuri.out");
vector<int> hashTable[HMAX];
int n, x, op, xHash;
bool ok;
in >> n;
for(int i = 0; i < n; i++) {
in >> op >> x;
xHash = mHash(x);
ok = true;
switch (op) {
case 1:
for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
if(*j == x) {
ok = false;
break;
}
if(ok)
hashTable[xHash].push_back(x);
break;
case 2:
for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
if(*j == x) {
hashTable[xHash].erase(j);
break;
}
break;
case 3:
for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
if(*j == x) {
ok = false;
out << 1 << endl;
break;
}
if(ok)
out << 0 << endl;
break;
}
}
in.close();
out.close();
return 0;
}