Cod sursa(job #854413)

Utilizator bogdan93Grigorescu Bogdan bogdan93 Data 13 ianuarie 2013 15:54:21
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.4 kb
#include <cstdlib>
#include <cstdio>
#include <vector>
#define mod 666013

using namespace std ;

vector <int> hash [ mod ] ;
int N , op , x ;

void adauga ()
{
    bool ok = 1 ;
    for ( int i = 0 ; i < hash [ x % mod ].size () ; i++ )
        if ( x ==  hash [ x % mod ][ i ] ) ok = 0 ;
    if ( ok )   hash [ x % mod ].push_back ( x ) ;

}
void sterge ()
{
    int ok = 0 ;
    int m = x % mod ;
    vector <int>::iterator it ;
    for ( it = hash [ m ].begin () ; it < hash [ m ].end () ; it++ )
        if ( x == *it )
            {
                ok = 1 ;
                goto here ;

            }
    here:
    if ( ok ) hash [ m ].erase ( it ) ;
}
int cauta ()
{
    for ( int i = 0 ; i < hash [ x % mod ].size () ; i++ )
        if ( x == hash [ x % mod ][ i ] ) return 1 ;
   return 0 ;
}
int main ()
{
    FILE *fin , *fout ;
    fin = fopen ( "hashuri.in" , "rt" ) ;
    fout = fopen ( "hashuri.out" , "wt" ) ;

    fscanf ( fin , "%d" , &N ) ;

    for ( int i = 1 ; i <= N ; i++ )
    {
        fscanf ( fin , "%d %d" , &op , &x ) ;
        if ( op == 1 )
        {
            adauga () ;
            continue ;
        }
        if ( op == 2 )
        {
            sterge () ;
            continue ;
        }
        int a = cauta () ;
        fprintf ( fout , "%d\n" , a ) ;


    }
    fclose ( fin ) ;
    fclose ( fout ) ;

    return 0 ;
}