Cod sursa(job #2229538)

Utilizator nicolaefilatNicolae Filat nicolaefilat Data 7 august 2018 10:55:13
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <fstream>
#include <vector>
#define MOD 999983

using namespace std;

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

vector< vector<int> > v;

void hash_insert( int x )
{
    int modulo = x % MOD;
    v[modulo].push_back(x);
}

void hash_erase( int x )
{
    int modulo = x % MOD;
    for (int i = 0 ; i < v[modulo].size(); i++){
        if (v[modulo][i] == x ){
            v[modulo].erase(v[modulo].begin()+i);
            return;
        }
    }
}

bool hash_find(int x)
{
    int modulo = x % MOD;
    for (int i = 0 ; i < v[modulo].size(); i++)
        if (v[modulo][i] == x )
            return true;
    return false;
}

int main()
{
    int n,op,x;
    in >> n;
    v = vector< vector<int> >(MOD);

    for (int i = 1; i <= n; i++ )
    {
        in >> op >> x;
        if (op == 1)
            hash_insert(x);
        else
        if (op == 2)
            hash_erase(x);
        else
            out << hash_find(x) << "\n";
    }
    return 0;
}