Cod sursa(job #2622633)

Utilizator dianapingu1Diana Vasiliu dianapingu1 Data 1 iunie 2020 16:53:14
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;

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

const int mod = 666013;
vector<int> hashT[mod];

bool cauta(int x)
{
    int hashValue = x % mod;
    for (auto i : hashT[hashValue]) {
        if (i == x)
            return true;
    }
    return false;
}

void inserare(int x)
{
    if (!cauta(x)) {
        int hashValue = x % mod;
        hashT[hashValue].push_back(x);
    }
}


void stergere(int x)
{
    if (cauta(x)) {
        int hashValue = x % mod;
        for (unsigned i=0; i<hashT[hashValue].size(); i++) {
            if (hashT[hashValue][i] == x) {
                hashT[hashValue].erase(hashT[hashValue].begin() + i);
                break;
            }
        }
    }
}


int main()
{
    int n,op,x;

    fin>>n;
    for (int i=0; i<n; i++) {
        fin>>op>>x;
        switch(op) {
        case 1:
            inserare(x);
            break;
        case 2:
            stergere(x);
            break;
        case 3:
            fout<<cauta(x)<<'\n';
            break;
        }
    }
}