Cod sursa(job #1568165)

Utilizator CTI_KnightCir Constantin CTI_Knight Data 13 ianuarie 2016 22:27:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
# include <fstream>
# include <algorithm>
# include <unordered_map>
# define endl "\n"

using namespace std;

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

unordered_map < int, int > Hash;

void inserare ( int x )
{
    Hash[x] ++;
}

void stergere ( int x )
{
    Hash.erase( x );
}

bool cautare ( int x )
{
    if ( Hash.find(x) != Hash.end() )
        return 1;
    return 0;
}

int main ()
{
    int n, x, optiune;
    f >> n;
    for ( int i = 1; i <= n; i ++ )
    {
        f >> optiune >> x;
        if ( optiune == 1 )
            inserare ( x );
        else
            if ( optiune == 2 )
                stergere ( x );
            else
                g << cautare ( x ) << endl;
    }

    return 0;
}