Cod sursa(job #2622866)

Utilizator florian_petrutCoaje Petrut florian_petrut Data 1 iunie 2020 23:33:30
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<int> hashTable[66013];

void Add(int x){
    hashTable[x % 66013].push_back(x);
}

void Delete(int x){
    int m = x % 66013;
    for (int i = 0; i < hashTable[m].size(); i++)
        if(hashTable[m][i] == x)
            hashTable[m].erase(hashTable[m].begin()+i);

}

int Search(int x){
    int m = x % 66013;
    for (int i = 0; i < hashTable[m].size(); i++)
        if(hashTable[m][i] == x)
            return 1;

    return 0;
}

int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int n, op, x;
    f>>n;
    for(; n; n--){
        f >> op >> x;
        if(op == 1)
           Add(x);
        else
            if(op == 2)
                Delete(x);
            else
                g << Search(x) << '\n';
        }
    f.close();
    g.close();
    return 0;

}