Cod sursa(job #2795890)

Utilizator LuciBBadea Lucian LuciB Data 7 noiembrie 2021 10:18:12
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <stdio.h>
#include <vector>
#include <ctype.h>
#define CARDINAL 276997
#define HASH_SIZE 100007
using namespace std;

FILE *fin, *fout;

vector<long long> hTable[HASH_SIZE];

void add(long long x) {
    hTable[x % HASH_SIZE].push_back(x);
}

bool search( long long x ) {
    int h, i;
 
    h = x % HASH_SIZE;
    i = 0;
    while(i < hTable[h].size() && hTable[h][i] != x)
        i++;
 
    return i < hTable[h].size();
}

long long readInt() {
    long long n = 0;
    char ch;
    while(!isdigit(ch = fgetc(fin)));
    do {
        n = n * 10 + ch - '0';
    }while(isdigit(ch = fgetc(fin)));

    return n;
}

int main() {
    long long n, i, ans;
    long long x;
    fin = fopen("dtcsu.in", "r");
    for(i = 0; i < CARDINAL; i++) {
        x = readInt();
        add(x);
    }
    n = readInt();
    ans = 0;
    for(i = 0; i < n; i++) {
        x = readInt();
        ans += search(x);
    }
    fclose(fin);

    fout = fopen("dtcsu.out", "w");
    fprintf(fout, "%lld", ans);
    fclose(fout);
    return 0;
}