题解 | #配置文件恢复#
配置文件恢复
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) {
if (it.find(str) == 0) {
num++;
tmp = it;
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_1 = str.substr(0, str.find(' '));
vector<string> vec;
for (auto it : S_) {
string it_ = it.substr(0, it.find(' '));
if (it_.find(command_1) == 0) vec.push_back(it);
}
string command_2 = str.substr(str.find(' ') + 1);
int num = 0;
string result = "other";
for (auto it : vec) {
string it_ = it.substr(it.find(' ') + 1);
if (it_.find(command_2) == 0) {
num++;
result = it;
if (num > 1) {
result = "other";
break;
}
}
}
cout<< umap[result]<<endl;
}
}
}
// 64 位输出请用 printf("%lld")
