Cod sursa(job #2745785)

Utilizator linte_robertLinte Robert linte_robert Data 26 aprilie 2021 23:50:56
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include <vector>
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

int numar_prim = 666013;

void operatie_1( vector < int > &tabel_hash, int numar ){
    if( tabel_hash[numar%numar_prim] != numar ){
        tabel_hash[numar%numar_prim] = numar;
    }
}
void operatie_2( vector < int > &tabel_hash, int numar ){
    if( tabel_hash[numar%numar_prim] == numar ){
        tabel_hash[numar%numar_prim] = numar_prim;
    }
}
int operatie_3( vector < int > &tabel_hash, int numar ){
    if( tabel_hash[numar%numar_prim] == numar ) return 1;
    else return 0;
}
int main(){
    vector < int > tabel_hash;
    ifstream fin( "hashuri.in" );
    ofstream fout( "hashuri.out" );
    int n;
    fin >> n;
    for( int i = 0; i < numar_prim; i++ ){
        tabel_hash.push_back( numar_prim );
    }
    for( int i = 0; i < n; i++ ){
        int operatie, numar;
        fin >> operatie >> numar;
        if( operatie == 1 ) operatie_1( tabel_hash, numar );
        if( operatie == 2 ) operatie_2( tabel_hash, numar );
        if( operatie == 3 ) fout << operatie_3( tabel_hash, numar ) << endl;
    }
}