Cod sursa(job #2406277)

Utilizator alexalghisiAlghisi Alessandro Paolo alexalghisi Data 15 aprilie 2019 16:42:23
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>
#define KEY 666013
#define pb push_back
#define un unsigned
using namespace std;

vector<int> hash[KEY];

void insert(int &x)
{
    int nivel=x%KEY;
    for(un int i=0;i<hash[nivel].size();++i)
        if(hash[nivel][i]==x)
            return;
    hash[nivel].pb(x);
}
void erase(int &x)
{
    int nivel=x%KEY;
    for(const int i=0;i<hash[nivel].size();++i)
        if(hash[nivel][i]==x)
        {
            swap(hash[nivel][i],hash[nivel].back());
            hash[nivel].pop_back();
            return;
        }
}
bool find(int &x)
{
    int nivel=x%KEY;
    for(un int i=0;i<hash[nivel].size();++i)
        if(hash[nivel][i]==x)
            return true;
    return false;
}
int main()
{
    int n;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f>>n;
    for(int i=1;i<=n;++i)
    {
        int op,x;
        f>>op>>x;
        if(op==1)
            insert(x);
        if(op==2)
            erase(x);
        if(op==3)
            g<<find(x)<<"\n";
    }
    return 0;
}