题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; vector<string> word = {"reset", "board", "add", "delete", "reboot", "backplane", "abort"}; while (getline(cin, s)) { bool doublepart = false; int count = 0; string s1, s2; while (count != s.size() && s[count] != ' ') { s1.push_back(s[count]); ++count; } if (count == s.size()) { if (word[0].find(s1) == string::npos) { cout << "unknown command" << endl; continue; } else { cout << "reset what" << endl; continue; } } ++count; while (count != s.size()) { s2.push_back(s[count]); ++count; } int flag = 0; if (word[0].find(s1) == 0) { if (word[1].find(s2) == 0) { flag = 2; } else { cout << "unknown command" << endl; continue; } } if (word[1].find(s1) == 0) { if (word[2].find(s2) == 0) { if (flag != 0) { cout << "unknown command" << endl; continue; } else { flag = 3; } } else if (word[3].find(s2) == 0) { if (flag != 0) { cout << "unknown command" << endl; continue; } else { flag = 4; } } else { cout << "unknown command" << endl; continue; } } if (word[4].find(s1) == 0) { if (word[5].find(s2) == 0) { if (flag != 0) { cout << "unknown command" << endl; continue; } else { flag = 5; } } else { cout << "unknown command" << endl; continue; } } if (word[5].find(s1) == 0) { if (word[6].find(s2) == 0) { if (flag != 0) { cout << "unknown command" << endl; continue; } else { flag = 6; } } else { cout << "unknown command" << endl; continue; } } if (flag == 0) { cout << "unknown command" << endl; continue; } if (flag == 2) { cout << "board fault" << endl; continue; } if (flag == 3) { cout << "where to add" << endl; continue; } if (flag == 4) { cout << "no board at all" << endl; continue; } if (flag == 5) { cout << "impossible" << endl; continue; } if (flag == 6) { cout << "install first" << endl; continue; } } } // 64 位输出请用 printf("%lld")
这题纯傻逼的