Pagini recente » Cod sursa (job #2014658) | Monitorul de evaluare | Cod sursa (job #1001052) | B.M.D. | Cod sursa (job #3177466)
#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_SIZE1 1000007
#define HASH_SIZE2 1000021
int computehash(ll x,int hbase,int hsize)
{
int strhash=0;
while(x)
{
strhash = (strhash * hbase + x%10)%hsize;
x/=10;
}
return strhash;
}
unordered_map<int,bool> M1,M2;
int main()
{
for(int i=1;i<=276997;i++)
{
ll x;
fin >> x;
M1[computehash(x,HASH_BASE,HASH_SIZE1)]=1;
M2[computehash(x,HASH_BASE,HASH_SIZE2)]=1;
}
int q;
fin >> q;
int cnt=0;
while(q--)
{
int x;
fin >> x;
cnt += M1[computehash(x,HASH_BASE,HASH_SIZE1)] && M2[computehash(x,HASH_BASE,HASH_SIZE2)];
}
fout << cnt;
}