关注
我的是这#include <fstream>
(31579)#include <iostream>
#include <numeric>
(30195)#include <sstream>
#include <string>
(30191)#include <vector>
using namespace std;
int finded = false;
struct Node {
string val;
Node* father;
vector<Node*> next{};
Node(string val)
: val(val), father(nullptr) {}
};
void deal(string line, Node* root) {
if (line.find('-') == string::npos) {
Node* one = new Node(line);
root->next.emplace_back(one);
one->father = root;
} else {
size_t start = line.find('-');
string lline = line.substr(start + 1, line.size() - start - 1);
root = root->next.back();
deal(lline, root);
}
}
void pri(Node* root, string str, const string& keyword) {
if (root->val.find(keyword) != string::npos) {
cout << str + root->val << endl;
}
for (const auto& r : root->next) {
pri(r, str + root->val, keyword);
}
}
int main() {
std::string keyword;
std::cin >> keyword; // 读取关键字
int count = 0;
std::cin >> count;
Node *vroot = new Node("/"), *cur = vroot;
for (int i = 0; i < count; ++i) {
std::string line;
std::cin >> line;
cur = vroot;
deal(line, cur);
}
// for(const auto& r : vroot->next[0]->next[0]->next) {
// cout << r->val << endl;
// }
pri(vroot, "", keyword);
return 0;
}
查看原帖
点赞 评论
牛客热帖
更多
正在热议
更多
# 你的实习产出是真实的还是包装的? #
35182次浏览 433人参与
# 牛友的志愿填报指南 #
63010次浏览 484人参与
# 厦门银行科技岗值不值得投 #
15690次浏览 359人参与
# 你的实习什么时候入职 #
366778次浏览 2355人参与
# 学历VS实习,哪个更重要? #
1750次浏览 49人参与
# 工作上你捅过哪些篓子? #
68317次浏览 315人参与
# uu们,春招你还来吗? #
63141次浏览 739人参与
# 面试紧张时你会有什么表现? #
34043次浏览 207人参与
# 面试中,你被问过哪些奇葩问题? #
96229次浏览 1264人参与
# 面试被问到不会的问题,你怎么应对? #
25876次浏览 648人参与
# 你都用vibe coding做过什么? #
21842次浏览 816人参与
# 机械人,签完三方你在忙什么? #
83932次浏览 266人参与
# 你觉得大几开始实习最合适? #
30034次浏览 309人参与
# AI Coding实战技巧 #
15425次浏览 299人参与
# 你见过哪些招聘隐形歧视? #
24870次浏览 214人参与
# 国庆前的秋招小结 #
291250次浏览 1742人参与
# 哔哩哔哩笔试 #
35138次浏览 142人参与
# 如果人生可以debug你会改哪一行? #
13010次浏览 167人参与
# 秋招特别不鸣谢 #
93224次浏览 685人参与
# 应届生被毁约被毁意向了怎么办 #
65374次浏览 313人参与
# 海康威视求职进展 #
132284次浏览 551人参与

