题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
//双字串输入拆分+双命令拆分+vector容器,简单直接
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
string str;
string sigle = "reset";
vector<vector<string>> tp1{{"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(sigle.find(str) == 0){
cout << "reset what" <<endl;
}else{
cout << "unknown command" <<endl;
}
}else{
int l = str.find(' ');
string str1 = str.substr(0, l);
string str2 = str.substr(l+1, str.length() -l - 1);
int count = 0;
string ans;
for(int i = 0 ; i < 5; i ++ ){
if(tp1[i][0].find(str1) == 0 && tp1[i][1].find(str2) == 0){
count ++ ;
ans = tp1[i][2];
}
}
if(count == 1){
cout << ans <<endl;
}else{
cout << "unknown command" <<endl;
}
}
}
return 0;
}