Pagini recente » Cod sursa (job #1674328) | Cod sursa (job #222733) | Cod sursa (job #2017274) | Cod sursa (job #1039814) | Cod sursa (job #3246345)
#include <vector>
#include <list>
#include <fstream>
#include <iostream>
class HashMap{
private:
std::vector<std::list<unsigned int>> map;
int hash(unsigned int x){
return x % 10'000'000;
}
public:
HashMap() : map(10'000'000){}
bool insert(unsigned int x){
int hash_code = hash(x);
map[hash_code].push_back(x);
if(map[hash_code].size() == 1)
return false;
return true;
}
bool find(unsigned int x){
int hash_code = hash(x);
for(auto it = map[hash_code].begin(); it != map[hash_code].end(); ++it){
if(*it == x)
return true;
}
return false;
}
void remove(unsigned int x){
int hash_code = hash(x);
for(auto it = map[hash_code].begin(); it != map[hash_code].end(); ++it){
if(*it == x){
map[hash_code].erase(it);
return;
}
}
}
};
int main(){
std::ifstream in("hashuri.in");
std::ofstream out("hashuri.out");
int teste, num, op;
HashMap my_map;
in>>teste;
for(int i = 0; i < teste; i++){
in>>op>>num;
if(op == 1){
my_map.insert(num);
}else if(op == 2){
my_map.remove(num);
}else{
if(my_map.find(num))
out<<"1\n";
else
out<<"0\n";
}
}
}