Cod sursa(job #2166219)

Utilizator MentaPopa Marius-Catalin Menta Data 13 martie 2018 16:07:30
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include <vector>
#include <fstream>
#include <iostream>

using namespace std;


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

const int mod = 666013;
int n, op, nr;

vector <int> h[mod];

bool hfind( int x )
{
    int y = x % mod ;
    vector <int>::iterator it;
    if ( h[y].empty() )
        return false;
    else
        for( it = h[y].begin() ; it != h[y].end() ; ++it )
            if( (*it) == x )
                return true;

    return false;
}

void hpush(int x)
{
    int y = x % mod;
    if ( !hfind(x))
        h[y].push_back(x);
}

void hdelete ( int x)
{
    int y = x % mod;
    vector <int>::iterator it;
    if ( hfind(x) )
        {
            for(it = h[y].begin() ; (*it) != x ; ++it );
            h[y].erase(it);
        }

}


int main()
{
    f>>n;
    int i;
    for( i = 0 ; i < n ; i++ )
    {
        f>>op>>nr;

        switch (op)
        {
        case 1:
            hpush(nr);
                break;
        case 2:
            hdelete(nr);
            break;
        case 3:
            g<<hfind(nr)<<"\n";
            break;
        }

    }
}