Cod sursa(job #2733830)

Utilizator Stefan_BerlinschiStefan-Cristian Berlinschi Stefan_Berlinschi Data 30 martie 2021 22:59:37
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.3 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

#define PRIM 10000

// ifstream fin("input.txt");
// ofstream fout("output.txt");

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

vector<int> Hash[PRIM];

int operatie_3 (int x) {
    int indice = x % PRIM;

    for (unsigned int i = 0; i < Hash[indice].size(); i++) {
        if (Hash[indice][i] == x)
            return 1;
    }

    return 0;
}

void operatie_1 (int x) {
    int indice = x % PRIM;

    if (operatie_3(x) == 0)
        Hash[indice].push_back(x);
}

void operatie_2 (int x) {
    int indice = x % PRIM;
    int contor = 0, pozitie;

    for (unsigned int i = 0; i < Hash[indice].size(); i++) {
        if (Hash[indice][i] == x) {
            contor = 1;
            pozitie = i;
        }
    }

    if (contor == 1) {
        Hash[indice].erase(Hash[indice].begin() + pozitie - 1);
    }
}

int main() {

    int n, opcode, nr;
    fin >> n;

    for (int i = 0; i < n; i ++) {
        fin >> opcode >> nr;

        if (opcode == 1) {
            operatie_1(nr);
        }

        if (opcode == 2) {
            operatie_2(nr);
        }

        if (opcode == 3) {
            fout << operatie_3(nr) << '\n';
        }
    }
    
    return 0;
}