Pagini recente » Cod sursa (job #1644671) | Cod sursa (job #192337) | Cod sursa (job #540936) | Cod sursa (job #2849354) | Cod sursa (job #3129212)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Hash{
private:
int hash_mod;
int* hash_array;
public:
Hash(int hash_mod = 666013){
this->hash_mod = hash_mod;
this->hash_array = new int[hash_mod];
}
bool is_in(int n){
return this->hash_array[n % this->hash_mod] != 0;
}
void insert(int n){
this->hash_array[n % this->hash_mod] = n;
}
void remove(int n){
if(this->is_in(n) == false) return;
this->hash_array[n % this->hash_mod] = 0;
}
};
fstream f("hashuri.in");
ofstream g("hashuri.out");
int main(){
Hash hash;
int n, op, no;
f >> n;
while(n){
f >> op >> no;
if(op == 1){
hash.insert(no);
}
else if(op == 2){
hash.remove(no);
}
else{
g << (hash.is_in(no) == true) << endl;
}
n--;
}
return 0;
}