Cod sursa(job #3177461)

Utilizator paull122Paul Ion paull122 Data 29 noiembrie 2023 10:52:44
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");
#define HASH_BASE 73
#define HASH_SIZE 1000007

int computehash(ll x)
{
    int strhash=0;
    while(x)
    {
        strhash = (strhash * HASH_BASE + x%10)%HASH_SIZE;
        x/=10;
    }
    return strhash;
}

unordered_map<int,bool> M;

int main()
{
    for(int i=1;i<=276997;i++)
    {
        ll x;
        fin >> x;
        M[computehash(x)]=1;
    }
    int q;
    fin >> q;
    int cnt=0;
    while(q--)
    {
        int x;
        fin >> x;
        cnt += M[computehash(x)];
    }
    fout << cnt;
}