Cod sursa(job #2745330)

Utilizator gabrielanideleaNidelea Gabriela-Andreea gabrielanidelea Data 26 aprilie 2021 13:16:09
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> h[1000];
int hashh(int x){
    return x%991;
}
bool semaf(int x){
    int ind = hashh(x);
    for(int i=0;i<h[ind].size();i++){
        if(h[ind][i] == x) return true;
    }
    return false;
}
void push(int x){
    if(!semaf(x)){
        int ind = hashh(x);
        h[ind].push_back(x);
    }
}
void pop(int x){
    int ind = hashh(x);
    for(int i=0;i<h[ind].size();i++){
        if(h[ind][i]==x){
            h[ind].erase(h[ind].begin()+i);
            return;
        }
    }
}
int main(){
    int n, operatie, x;
    f>>n;
    for(int i=0;i<n;i++){
        f>>operatie>>x;
        if(operatie == 1)
            push(x); // op 1=> adaug x
        else{
            if(operatie == 2)
                pop(x); // op 2=> sterg \x
            else g<<semaf(x)<<'\n'; // afisez pe varianta 3
        }
    }
    return 0;
}