Cod sursa(job #2740800)

Utilizator andre.anghelacheAndreea Anghelache andre.anghelache Data 14 aprilie 2021 13:01:43
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int modulo=541523;
vector<vector<int>> myhash(modulo);

void insereaza(int x){
    int cheie=x%modulo;
    for(auto elem:myhash[cheie])
        if(elem==x)
            return;
    myhash[cheie].push_back(x);
}

void sterge(int x){
    int cheie=x%modulo;
    for(auto iterator=myhash[cheie].begin(); iterator<myhash[cheie].end(); iterator++)
        if(*iterator==x)
        {
            myhash[cheie].erase(iterator);
            return;
        }
}

bool gaseste(int x){
    int cheie=x%modulo;
    for(auto elem:myhash[cheie])
        if(elem==x)
            return true;
    return false;
}

int main() {

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

    int nr_operatii, operatie, element;

    in>>nr_operatii;

    for(int i=0; i<nr_operatii; i++)
    {
        in>>operatie>>element;
        if(operatie==1)
            insereaza(element);
        if(operatie==2)
            sterge(element);
        if(operatie==3)
            out<<gaseste(element)<<"\n";

    }

    return 0;
}