题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include <iostream> #include <vector> #include <bits/stdc++.h> using namespace std; const vector<string> S{ "reset" }; const vector<string> S_{ "reset board", "board add", "board delete", "reboot backplane", "backplane abort" }; map<string, string> umap{ {"reset", "reset what"}, {"reset", "reset what"}, {"reset board", "board fault"}, {"board add", "where to add"}, {"board delete", "no board at all"}, {"reboot backplane", "impossible"}, {"backplane abort", "install first"}, {"other", "unknown command"} }; string find_(string str, vector<string> V) { int num = 0; string tmp = "other"; for (auto it : V) { string cur = it; if (it.find(' ') != string::npos){ it = it.substr(it.find(' ') + 1); } if (it.find(str) == 0) { num++; tmp = cur; if (num > 1) { tmp = "other"; break; } } } return tmp; } int main() { string str; while (getline(cin, str)) { if (str.find(' ') == string::npos) { cout << umap[find_(str, S)] << endl; } else { string command = str.substr(0, str.find(' ')); vector<string> vec; for (auto it : S_) { string it_ = it.substr(0, it.find(' ')); if (it_.find(command) == 0) vec.push_back(it); } string command_2 = str.substr(str.find(' ') + 1); cout<< umap[find_(command_2, vec)]<<endl; } } } // 64 位输出请用 printf("%lld")