题目传送门
1 /*
2 set的二分查找
3 如果数据规模小的话可以用O(n^2)的暴力想法
4 否则就只好一个一个的换(a, b, c),在set容器找相匹配的
5 */
6 #include <cstdio>
7 #include <cmath>
8 #include <string>
9 #include <cstring>
10 #include <iostream>
11 #include <algorithm>
12 #include <map>
13 #include <set>
14 #include <vector>
15 using namespace std;
16
17 int main(void)
18 {
19 //freopen ("C.in", "r", stdin);
20
21 set<string> s;
22 string tmp;
23 int n, m, mx;
24
25 while (cin >> n >> m)
26 {
27 mx = -1;
28 s.clear ();
29 for (int i=1; i<=n; ++i)
30 {
31 cin >> tmp;
32 s.insert (tmp);
33 int len = tmp.size ();
34 mx = max (mx, len);
35 }
36 if (n * m * mx < 1e8)
37 {
38 for (int j=1; j<=m; ++j)
39 {
40 cin >> tmp;
41 int cnt = 0;
42 set<string>::iterator it;
43 for (it=s.begin (); it!=s.end (); ++it)
44 {
45 if (it->size () == tmp.size ())
46 {
47 cnt = 0;
48 for (int j=0; j<it->size (); ++j)
49 {
50 if ((*it)[j] != tmp[j]) cnt++;
51 if (cnt > 1) break;
52 }
53 if (cnt == 1) break;
54 }
55 }
56 if (cnt == 1) cout << "YES" << endl;
57 else cout << "NO" << endl;
58 }
59 continue;
60 }
61
62 for (int i=1; i<=m; ++i)
63 {
64 cin >> tmp;
65 bool flag = false;
66 for (int j=0; tmp[j]!='