Cod sursa(job #2745699)

Utilizator Costin_PintilieHoratiu-Costin-Petru Pintilie Costin_Pintilie Data 26 aprilie 2021 21:57:34
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
#define prim 99079

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

struct HashMap{

vector<int> Map[prim];

void adauga(int x){
    int h = x%prim;
    if(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 = 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(find(Map[h].begin(),Map[h].end(),x) != Map[h].end()){
        return 1;
    }
    else{
        return 0;
    }

}

};
int n,i,operatie,x;
int main(){

HashMap hashMap;
fin>>n;

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

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

fin.close();
fout.close();
    return 0;
}