#include <bits/stdc++.h>
using namespace std;int main() {int N, M;cin >> N >> M;unordered_set<string> p;string s; for (int i = 0; i < N; i++) { // 生成所有前缀并存入集合cin >> s;string a;for (char c : s) {a += c;p.insert(a);}}for (int i = 0; i < M; i++) {cin >> s;cout << (p.count(s) ? "Y" : "N") << endl;}return 0;
}
使用 unordered_set.count()
判断某个查询字符串 Tj
是否存在于集合中