/***************
Problem from :
Problem describe :
data:
****************/
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<cstring>
#include<vector>
#include<string>
#define ll __int64
#define inf 0x3f3f3f3f3f
using namespace std;
char c[7];
int mark[1000005];
int getHash()
{
int key = 1;
int hash = 0;
for(int i=0; i<strlen(c); i++)
{
hash += key*c[i];
key *=131;
}
return hash;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int i, n, m, ans=0, len;
scanf("%d%d", &n, &m);
memset(mark, inf, sizeof(mark));
for(i=1; i<=n; i++)
{
scanf("%s", c);
mark[i] = getHash();
}
sort(mark+1, mark+n+1);
while(m--)
{
scanf("%s", c);
int hash = getHash();
int index = lower_bound(mark+1, mark+1+n, hash) - mark;
if(mark[index] == hash) ans++;
}
printf("%d\n", ans);
return 0;
}
ds 6.2 search name 寻人启事 (哈希hash)
最新推荐文章于 2021-12-14 21:57:10 发布