题解 | #配置文件恢复#

配置文件恢复

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();
    }
}

全部评论

相关推荐

在看数据的傻狍子很忙碌:学生思维好重,而心很急,自己想想真的能直接做有难度的东西吗?任何错误都是需要人担责的,你实习生可以跑路,你的同事领导呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务