题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include <iostream>
#include <sstream>
#include <map>
using namespace std;
map<string, string> mp = {{"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"}
};
int main() {
string str;
while (getline(cin, str)) {
bool flag = false;
string first, second;
if (str.find(' ') != string::npos) {
int p = str.find(' ');
first = str.substr(0, p);
second = str.substr(p + 1);
int k = 1;
string res;
for (auto it : mp) {
if (it.first.find(' ') != string::npos) {
int pos = it.first.find(' ');
string a = it.first.substr(0, pos);
string b = it.first.substr(pos + 1);
if (a.substr(0, first.size()) == first &&
b.substr(0, second.size()) == second) {
k--;
res = it.first;
}
}
}
if (k == 0) {
flag = true;
cout << mp[res] << endl;
}
} else {
string tem = "reset";
if (tem.substr(0, str.size()) == str) {
flag = true;
cout << mp[tem] << endl;
}
}
if (!flag) cout << "unknown command" << endl;
}
return 0;
}
