ICU152_QWQ_IS8 @ 2024-03-01 22:41:06
#include<bits/stdc++.h>
#define int long long
using namespace std;
int sp(char x){
if(x>='A'&&x<='Z')return x-'A';
else return x-'a'+26;
}
int id;
int cnt[3000005];
int trie[3000005][55];
void ins(string s){
int len=s.length();
int now=0;
for(int i=0;i<len;i++){
if(!trie[now][sp(s[i])]){
trie[now][sp(s[i])]=++id;
}
now=trie[now][sp(s[i])];
cnt[now]++;
}
}
int query(string s){
int len=s.length();
int now=0;
for(int i=0;i<len;i++){
if(!trie[now][sp(s[i])]){
return 0;
}
now=trie[now][sp(s[i])];
}
return cnt[now];
}
signed main(){
int t;
cin>>t;
while(t--){
int n,q;
cin>>n>>q;
for(int i=0;i<=id;i++){
for(int j=0;j<=54;j++){
trie[i][j]=0;
}
}
memset(cnt,0,sizeof(cnt));
id=0;
for(int i=1;i<=n;i++){
string s;
cin>>s;
ins(s);
}
while(q--){
string m;
cin>>m;
cout<<query(m)<<endl;
}
}
return 0;
}
by __NULL1F1CAT10N__ @ 2024-03-01 22:42:21
似乎输入的字符串还有数字
by __NULL1F1CAT10N__ @ 2024-03-01 22:43:10
@ICU152_QWQ_IS8
by ICU152_QWQ_IS8 @ 2024-03-01 22:43:45
@__f0r_1_1n_ran9e__ 谢
by tder @ 2024-03-01 22:53:40
@ICU152_QWQ_IS8 第二维要开到