sansesantongshun @ 2023-11-03 22:34:42
#include<bits/stdc++.h>
using namespace std;
int t,m,q,n,x,top=0;
bool ok;
char s[3000005];
struct node
{
int nxt[123],end;
} trie[3000005];
int main()
{
cin>>t;
while (t--)
{
scanf("%d%d",&m,&q);
while (m--)
{
scanf("%s",s+1);
n=strlen(s+1);
x=0;
for (int i=1;i<=n;++i)
{
if (trie[x].nxt[s[i]]==0)
trie[x].nxt[s[i]]=++top;
x=trie[x].nxt[s[i]];
++trie[x].end;
}
}
while (q--)
{
scanf("%s",s+1);
n=strlen(s+1);
x=0;
ok=1;
for (int i=1;i<=n;++i)
{
if (trie[x].nxt[s[i]]==0)
{
ok=0;
cout<<"0\n";
break;
}
x=trie[x].nxt[s[i]];
}
if (ok)
cout<<trie[x].end<<'\n';
}
for (int i=1;i<=top;++i)
{
for (char j=0;j<='z';++j)
trie[i].nxt[j]=0;
trie[i].end=0;
}
top=0;
}
}
by zhangxiao666 @ 2023-11-04 01:03:31
清空那个外层for循环从0开始
by sansesantongshun @ 2023-11-04 18:33:34
@zhangxiao666 你太尖了
by wjy2020 @ 2024-02-05 15:43:39
感谢,一样的错
by Lyy450605 @ 2024-04-27 16:10:33
感谢, 一样的错
by Dress @ 2024-07-20 09:32:54
感谢, 一样的错