我的是这#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; }
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务