Pagini recente » Cod sursa (job #1675694) | Cod sursa (job #1931269) | Cod sursa (job #867334) | Cod sursa (job #457183) | Cod sursa (job #832307)
Cod sursa(job #832307)
///timing 11:53 - 30 minutes
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("hashuri.in");
ofstream out ("hashuri.out");
class hash {
int Key;
vector <int> * H;
vector<int>::iterator it;
public:
hash() { Key = 0; H = new vector<int>[1]; };
hash(int);
void insert(int);
void erase(int);
int check(int);
};
hash :: hash(int K){
Key = K;
H = new vector <int> [K];
}
void hash :: insert (int value) {
int X = value % Key;
H[X].push_back(value);
}
void hash :: erase (int value) {
int X = value % Key;
for(it = H[X].begin(); it != H[X].end(); it++)
if(*it == value){
H[X].erase(it);
break;
}
}
int hash :: check(int value) {
int X = value % Key;
for(it = H[X].begin(); it != H[X].end(); it++)
if(*it == value) return 1;
return 0;
}
int main()
{
hash A(666013);
int N, operation, value;
in >> N;
while(N--){
in >> operation >> value;
switch (operation) {
case 1: A.insert(value); break;
case 2: A.erase(value); break;
case 3: out << A.check(value) << "\n"; break;
}
}
return 0;
}