题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
// HJ66-2 配置文件恢复.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { string str; string signal = "reset"; vector<vector<string>>dp = { {"reset","board","board fault"},{"board","add","where to add"}, {"board","delete","no board at all"},{"reboot","backplane","impossible"},{"backplane","abort","install first"} }; while (getline(cin, str)) { int n = count(str.begin(),str.end(),' '); if (n == 0) { if (signal.find(str) == 0) { cout << "reset what" << endl; } else { cout << "unknown command" << endl; } } else { int count = 0; string res = ""; int x = str.find(' '); string str1 = str.substr(0, x); string str2 = str.substr(x + 1); for (int i = 0; i < 5; i++) { if (dp[i][0].find(str1) == 0 && dp[i][1].find(str2) == 0) { res = dp[i][2]; count++; continue; } } if (count == 1) { cout << res << endl; } else { cout << "unknown command" << endl; } } } return 0; }