Koishi514ww @ 2024-11-20 18:59:28
#include<bits/stdc++.h>
using namespace std;
const int N = 3e6 + 5;
int trie[N][52], cnt, exist[N];
void insert(string& s) {
int p = 0;
for (int i = 0; i < s.size(); i++) {
int c = s[i] >= 'A' ? s[i] - 'A' + 26 : s[i] - 'a';
if (!trie[p][c]) trie[p][c] = ++cnt;
p = trie[p][c];
exist[p]++;
}
}
void query(string& s) {
int p = 0;
for (int i = 0; i < s.size(); i++) {
int c = s[i] >= 'A' ? s[i] - 'A' + 26 : s[i] - 'a';
if (!exist[p]&&p) {
cout << 0 << endl;
return;
}
p = trie[p][c];
}
cout << exist[p] << endl;
}
void clear() {
for (int i = 0; i <= cnt; i++) {
for (int j = 0; j < 52;j++) {
trie[i][j] = 0;
}
}
for (int i = 0; i <= cnt; i++) exist[i] = 0;
cnt = 0;
}
void koishi() {
int n, q; cin >> n >> q;
for (int i = 0; i < n; i++) {
string s; cin >> s;
insert(s);
}
for (int i = 0; i < q; i++) {
string s; cin >> s;
query(s);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
koishi();
clear();
}
}
by zmza @ 2024-11-20 19:05:10
@Koishi514ww 你没有包含数字