Cod sursa(job #2622841)

Utilizator florian_petrutCoaje Petrut florian_petrut Data 1 iunie 2020 22:31:00
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<int> hashtable[59999];
int n,x,op;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

bool cautare(int x){
    int index=x%59999;
        for(int i=0; i< hashtable[index].size(); i++)
                if(hashtable[index][i] == x)
            return 1;

    return 0;
}

void adaugare(int x){
    if(!cautare(x))
        hashtable[x%59999].push_back(x);
}
void stergere(int x){
    int m = x % 59999;
    for (int i = 0; i < hashtable[m].size(); i++)
        if(hashtable[m][i] == x)
            hashtable[m].erase(hashtable[m].begin()+i);
}
int main()
{
    f>>n;
    while(n--){
        f>>op>>x;
        if(op==1)
            adaugare(x);
            else if(op==2)
                stergere(x);
                else g<<cautare(x)<<endl;
    }
    return 0;
}