开新坑了,好像是第3个了
#include<cstdio>
#include<string.h>
const int N = 2e6+5;
const int M = 131;
const int INF = 0x3f3f3f3f;
using namespace std;
int T,n,m,Ans,no;
int cnt[N],t[N][M];
char ch[N];
inline int getnum(char K)
{
if(K>='A' && K<='Z') return K - 'A';
else if(K>='a' && K<='z') return K - 'a' + 26;
else return K -'0' + 52;
}
inline void insert(char str[])
{
int p = 0 , len = strlen(str);
for(int i=0;i<len;i++)
{
int c = getnum(str[i]);
if(!t[p][c]) t[p][c] = ++ no;
p = t[p][c];
cnt[p] ++ ;
}
}
inline int Find(char str[])
{
int p = 0 , len = strlen(str);
for(int i=0;i<len;i++)
{
int c = getnum(str[i]);
if(!t[p][c]) return 0;
p = t[p][c];
}
return cnt[p] ;
}
signed main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=0; i<=no; i++)
{
cnt[i] = 0 ;
for(int j=0; j<=M; j++)
t[i][j]=0;
}
no = 0;
for(int i=1;i<=n;i++)
{
scanf("%s",ch);
insert(ch);
}
for(int i=1;i<=m;i++)
{
scanf("%s",ch);
printf("%d\n",Find(ch));
}
}
}
标签:const,int,char,&&,include,字典
From: https://www.cnblogs.com/Low-key-smile/p/16739737.html