Cod sursa(job #2745306)

Utilizator gabrielanideleaNidelea Gabriela-Andreea gabrielanidelea Data 26 aprilie 2021 12:56:54
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.11 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n, op, x, ind;
vector<int> has[1000];
bool semafor(int x)
{
    ind = x%271;
    for(int i=0; i<has[ind].size(); i++)
    {
        if(has[ind][i] == x)
            return 1; // daca se gaseste in hash, return 1
    }
    return 0; // daca nu, 0
}
void push(int x)
{
    if(!semafor(x))
        has[x%271].push_back(x); // op de adaugare
}
void pop(int x)
{
    ind = x%271;
    for(int i=0; i<has[ind].size(); i++)
    {
        if(has[ind][i]==x)
        {
            has[ind].erase(has[ind].begin()+i);//op de stergere
            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<<semafor(x)<<endl; // pe varianta 3 afisez

        }
    }
    return 0;
}