Cod sursa(job #2895644)

Utilizator urluconceptualCiocan Alexandra-Diana urluconceptual Data 29 aprilie 2022 12:22:23
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;


int h(int x) {
    return x % 97;
}


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

    int nr, op;
    long int x;
    vector <list<long int>> hash(97);
    fin >> nr;
    for (int i = 0; i < nr; i++) {
        fin >> op >> x;
        int lista = h(x);
        auto itr = find(hash[lista].begin(), hash[lista].end(), x);
        switch (op) {
        case 1:
            if (itr == hash[lista].end())
                hash[lista].push_back(x);
        case 2:
            if (itr != hash[lista].end())
                hash[lista].remove(*itr);
        case 3:
            if (itr == hash[lista].end())
                fout << "0\n";
            else fout << "1\n";
        }
    }

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