Pagini recente » Cod sursa (job #3145343) | Cod sursa (job #214691) | Cod sursa (job #344216) | Cod sursa (job #2727880) | Cod sursa (job #972124)
Cod sursa(job #972124)
#include <fstream>
#include <vector>
#include <set>
using namespace std;
class Vector{
vector<int> v;
public:
void insert(int x){
v.push_back(x);
}
int find(int x){
for (size_t i = 0 ; i < v.size() ; i++)
if (v[i] == x)
return i;
return -1;
}
void erase(int poz){
if (poz == -1)
return;
v[poz] = v.back();
v.pop_back();
}
int end(){
return -1;
}
};
template<class CollisionSolver, int Size>
class HashTable{
CollisionSolver hash[Size];
public:
void insert(int x){
if (!find(x))
hash[x % Size].insert(x);
}
void erase(int x){
if (find(x))
hash[x % Size].erase( hash[x % Size].find(x) );
}
bool find(int x){
return hash[x % Size].find(x) != hash[x % Size].end();
}
};
HashTable<set<int>, 1> H;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int main(){
int times, tip, x;
in >> times;
while (times--){
in >> tip >> x;
if (tip == 1)
H.insert(x);
if (tip == 2)
H.erase(x);
if (tip == 3)
out << H.find(x) << "\n";
}
return 0;
}