思路:
1.
先把那m个排个序 此后每回二分+strncmp一下就好了
strncmp是个好东西啊……
2.
hash判判 (注意 hash会有冲突…………………….)
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,ans;
struct Node{char a[66];}node[10005],jy;
bool operator <(Node a,Node b){return strcmp(a.a,b.a)<=0;}
int main(){
scanf("%d%d",&m,&n),getchar();
for(int i=1;i<=m;i++)gets(node[i].a);
sort(node+1,node+1+m);
for(int i=1;i<=n;i++){
gets(jy.a);
int l=1,r=m,len=strlen(jy.a);
while(l<=r){
int Mid=(l+r)>>1,judge=strncmp(node[Mid].a,jy.a,len);
if(judge<0)l=Mid+1;
else if(judge>0)r=Mid-1;
else {ans++;break;}
}
}
printf("%d
",ans);
}
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
int m,n,f[1111][66],mod=1000000007,ans;
char a[1111][66],s[66];
signed main(){
scanf("%lld%lld",&m,&n),getchar();
for(int i=1;i<=m;i++)gets(a[i]);
for(int i=1;i<=m;i++){
int l=strlen(a[i]);
for(int j=0;j<l;j++){
f[i][j+1]=(f[i][j]*137+a[i][j])%mod;
}
}
for(int i=1;i<=n;i++){
gets(s);
int len=strlen(s),temp=0;
for(int j=0;j<len;j++)temp=(temp*137+s[j])%mod;
for(int j=1;j<=m;j++){
if(temp==f[j][len]){ans++;break;}
}
}
printf("%lld
",ans);
}