Cod sursa(job #2742504)

Utilizator Costin_PintilieHoratiu-Costin-Petru Pintilie Costin_Pintilie Data 21 aprilie 2021 03:20:08
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;
#define prim 99079

std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");

struct HashMap{

std::vector<int> Map[prim];

void adauga(int x){
    int h = x%prim;
    if(std::find(Map[h].begin(),Map[h].end(),x) == Map[h].end()){
        Map[h].push_back(x);
    }
}
void sterge(int x){
    int h = x%prim;
    auto elem = std::find(Map[h].begin(),Map[h].end(),x);
    if(elem != Map[h].end()){
        Map[h].erase(elem);
    }
}

int cauta(int x){
    int h = x%prim;

    if(std::find(Map[h].begin(),Map[h].end(),x) != Map[h].end()){
        return 1;
    }
    else{
        return 0;
    }

}

};
int n = 0;
int main(){

HashMap hashMap;
fin>>n;

for (int i = 0; i < n; i++){
    int operatie, x;
    fin>>operatie>>x;

    switch(operatie){
        case 1:
            hashMap.adauga(x);
            break;
        case 2:
            hashMap.sterge(x);
            break;
        case 3:
            fout<<hashMap.cauta(x)<<endl;
            break;
        }

}

fin.close();
fout.close();



    return 0;
}