题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
string strs = "reset";
vector<string> s1 = {"reset", "board", "board fault"};
vector<string> s2 = {"board", "add", "where to add"};
vector<string> s3 = {"board", "delete", "no board at all"};
vector<string> s4 = {"reboot", "backplane", "impossible"};
vector<string> s5 = {"backplane", "abort", "install first"};
while (getline(cin, str)) {
if (find(str.begin(), str.end(), ' ') == str.end()) {
if (strs.find(str) == 0) {
cout << "reset what" << endl;
} else cout << "unknown command" << endl;
} else {
int p = str.find(' ');
int count =0;
string str1 = str.substr(0, p);
string str2 = str.substr(p+1, str.length() - 1 - p);
string res;
if (s1[0].find(str1) == 0 && s1[1].find(str2) == 0) {
count++;
res =s1[2];
}
if (s2[0].find(str1) == 0 && s2[1].find(str2) == 0) {
count++;
res =s2[2];
}
if (s3[0].find(str1) == 0 && s3[1].find(str2) == 0) {
count++;
res =s3[2];
}
if (s4[0].find(str1) == 0 && s4[1].find(str2) == 0) {
count++;
res =s4[2];
}
if (s5[0].find(str1) == 0 && s5[1].find(str2) == 0) {
count++;
res =s5[2];
}
if(count !=1) {
cout << "unknown command" << endl;
}
else if(count ==1){
cout << res << endl;
}
}
str.clear();
}
}
腾讯云智研发成长空间 310人发布