1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n, m; int tot = 2; int t[150000][30]; int cnt[150000]; void add(string str) { int h = 1; for (char c : str) { int si = c - 'a'; if (t[h][si] <= 0) { t[h][si] = tot; tot++; } h = t[h][si]; } cnt[h]++; return; } int query(string str) { int h = 1, sum = 0; for (char c : str) { int si = c - 'a'; if (t[h][si] <= 0) { break; } h = t[h][si]; sum += cnt[h]; } return sum; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { string str; cin >> str; add(str); } while (m--) { string str; cin >> str; cout << query(str) << endl; } return 0; }
- 1
信息
- ID
- 1181
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者