Cod sursa(job #2744917)

Utilizator MihaelaDanilaDanila Mihaela MihaelaDanila Data 25 aprilie 2021 15:37:52
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector<int> h[100];

bool index(int x){
    int poz = x%31;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i] == x) return true;
    }
    return false;
}

void push(int x){
    if(!index(x)){
        h[x%31].push_back(x);
    }
}

void pop(int x){
    int poz = x%31;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i]==x){
            h[poz].erase(h[poz].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);
        else{
            if(operatie == 2) pop(x);
            else g<<index(x)<<'\n';
        }
    }
    return 0;
}