Cod sursa(job #3129212)

Utilizator willOcanaru Mihai will Data 13 mai 2023 14:00:54
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#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;
}