auto* nam = new std::string[n + 5]; for (int i = 1; i <= n; i++) { int k; std::cin >> k; std::getline(std::cin, nam[i]); // 还有换行符未被 cin 读入 std::getline(std::cin, nam[i]);
std::string k; for (int i = 1; i <= m; i++) { std::string s; std::cin >> s; k += s; // 同理 } query(k);
for (int i = 1; i <= n; i++) { if (ans[i]) { // 出现过就输出 std::cout << nam[i] << '\n'; } }
return0; }
voidbuild(){ std::queue<int> q; for (int i = 0; i < CHA_SIZE; i++) { if (tree[0][i]) { q.push(tree[0][i]); } } while (!q.empty()) { int x = q.front(); q.pop(); for (int i = 0; i < CHA_SIZE; i++) { if (!tree[x][i]) { tree[x][i] = tree[nxt[x]][i]; } else { q.push(tree[x][i]); nxt[tree[x][i]] = tree[nxt[x]][i]; } } } }
voidinit(){ int cnt = 0; for (int i = '1'; i <= '8'; ++i) { tt[i] = ++cnt; } tt['B'] = ++cnt; tt['K'] = ++cnt; tt['N'] = ++cnt; tt['P'] = ++cnt; tt['Q'] = ++cnt; tt['R'] = ++cnt; for (int i = 'a'; i <= 'h'; ++i) { tt[i] = ++cnt; } tt['x'] = ++cnt; }
voidinsert(std::string s, int c){ int x = 0; for (int i = 0; s[i]; i++) { int ch = tt[s[i]]; if (!tree[x][ch]) { tree[x][ch] = ++tot; } x = tree[x][ch]; } exi[x] = c; }
voidquery(std::string s){ int x = 0; for (int i = 0; s[i]; i++) { int ch = tt[s[i]]; x = tree[x][ch]; for (int j = x; j; j = nxt[j]) { ans[exi[j]]++; } } }