Cod sursa(job #2623011)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 2 iunie 2020 14:23:01
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>

#define modulo 55555

using namespace std;

class Hash{
    vector<int> el[modulo];

    static int get_m(int x){
        return x%modulo;
    }

public:
    void insert(int x){
        el[get_m(x)].push_back(x);
    }

    void remove(int x){
        int m = get_m(x);
        for(int i=0;i<el[m].size();i++)
            if(el[m][i]==x)
                el[m].erase(el[m].begin()+i);
    }

    bool contains(int x){
        int m = get_m(x);
        for(int i : el[m])
            if(i==x)
                return true;
        return false;
    }
};

int main() {
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");

    int n, op, x;
    Hash* hash = new Hash();
    fin>>n;
    while(n--){
        fin>>op>>x;
        if(op==1){
            hash->insert(x);
            continue;
        }
        if(op==2){
            hash->remove(x);
            continue;
        }
        fout<<(hash->contains(x))<<'\n';
    }
    delete hash;
    fin.close();
    fout.close();
    return 0;
}