Cod sursa(job #2894085)

Utilizator Petrica81Simion Petrica Petrica81 Data 27 aprilie 2022 11:29:01
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <vector>
#define nrmare 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> hashuri[nrmare];
bool cautare(int x){
    for(auto i = hashuri[x%nrmare].begin(); i!=hashuri[x%nrmare].end();i++) {
        if (*i == x)
            return 1;
    }
    return 0;
}
void stergere(int x) {
    for (auto i = hashuri[x % nrmare].begin(); i != hashuri[x % nrmare].end(); i++) {
        if (*i == x) {
            hashuri[x % nrmare].erase(i);
            i = hashuri[x % nrmare].end();
        }
    }
}
void adaugare(int x) {
    if (!cautare(x)) {
        hashuri[x%nrmare].push_back(x);
    }
}

int main() {
    int i;
    f>>i;
    while(i>=0){
        cout<<1;
        int aux,x;
        f>>aux>>x;
        if(aux == 1){
            adaugare(x);
        }
        if(aux == 2){
            stergere(x);
        }
        if(aux == 3){
            g<<cautare(x)<<'\n';
        }
        --i;
    }
    return 0;
}