Cod sursa(job #2745328)

Utilizator gabrielanideleaNidelea Gabriela-Andreea gabrielanidelea Data 26 aprilie 2021 13:11:22
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n, x, op;
vector<int> h[1000];
bool semaf(int x){
    int poz = x%991;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i] == x) return true; // 1 daca se gaseste
    }
    return false; //0 daca nu
}
void push(int x){
    if(!semaf(x)){
        h[x%991].push_back(x); // daca nu e in hash deja, il adaug
    }
}
void pop(int x){
    int poz = x%991;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i]==x){
            h[poz].erase(h[poz].begin()+i);// il sterg pe x din hash
            return;
        }
    }
}
int main()
{
    f>>n;
    for(int i=0; i<n; i++)
    {
        f>>op>>x; // citesc fiecare pereche (operatie, numar)
        if(op == 1)
            push(x); // 1 => adaug cu push
        else
        {
            if(op == 2)
                pop(x); // 2 => sterg cu pop
            else
                g<<semaf(x)<<endl; // pe varianta 3 afisez

        }
    }
    return 0;
}