Cod sursa(job #3132700)

Utilizator Ana_22Ana Petcu Ana_22 Data 23 mai 2023 16:31:41
Problema Dtcsu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <vector>
#include <stdio.h>
#define NR 276997
#define HASHSIZE 1007

using namespace std;

vector<long long> h[HASHSIZE];
int cnt;

FILE *fin, *fout;

int gethash( long long no ) {
    return no % HASHSIZE;
}

void readline() {
    char ch = fgetc( fin ), str[20];
    unsigned int i = 0;
    while( ch != '\n' ) {
        str[i++] = ch;
        ch = fgetc( fin );
    }
    long long no = 0;
    for( unsigned int j = 0; j < i; j++ )
        no = no * 10 + str[j] - '0';
    int key = gethash( no );
    i = 0;
    while( i < h[key].size() && h[key][i] != no )
        i++;
    if( i == h[key].size() )
        h[key].push_back( no );
}

void hashfind( long long n ) {
    int key = gethash( n );
    unsigned int i = 0;
    while( i < h[key].size() && h[key][i] != n )
        i++;
    if( i < h[key].size() )
        cnt++;
}

int main() {
    int i, q;
    long long n;
    fin = fopen( "dtcsu.in", "r" );
    fout = fopen( "dtcsu.out", "w" );
    for( i = 0; i < NR; i++ ) {
        readline();//hashadd()
    }
    fscanf( fin, "%d", &q );
    for( i = 0; i < q; i++ ) {
        fscanf( fin, "%lld", &n );
        hashfind( n );
    }
    fprintf( fout, "%d", cnt );
    fclose( fin );
    fclose( fout );
    return 0;
}