题解 | #配置文件恢复#

配置文件恢复

https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    string s;
    vector<string> word = {"reset", "board", "add", "delete", "reboot", "backplane", "abort"};
    while (getline(cin, s)) {
        bool doublepart = false;
        int count = 0;
        string s1, s2;
        while (count != s.size() && s[count] != ' ') {
            s1.push_back(s[count]);
            ++count;
        }
        if (count == s.size()) {
            if (word[0].find(s1) == string::npos) {
                cout << "unknown command" << endl;
                continue;
            } else {
                cout << "reset what" << endl;
                continue;
            }
        }
        ++count;
        while (count != s.size()) {
            s2.push_back(s[count]);
            ++count;
        }
        int flag = 0;
        if (word[0].find(s1) == 0) {
            if (word[1].find(s2) == 0) {
                flag = 2;
            } else {
                cout << "unknown command" << endl;
                continue;
            }
        }
        if (word[1].find(s1) == 0) {
            if (word[2].find(s2) == 0) {
                if (flag != 0) {
                    cout << "unknown command" << endl;
                    continue;
                } else {
                    flag = 3;
                }
            } else if (word[3].find(s2) == 0) {
                if (flag != 0) {
                    cout << "unknown command" << endl;
                    continue;
                } else {
                    flag = 4;
                }
            } else {
                cout << "unknown command" << endl;
                continue;
            }
        }
        if (word[4].find(s1) == 0) {
            if (word[5].find(s2) == 0) {
                if (flag != 0) {
                    cout << "unknown command" << endl;
                    continue;
                } else {
                    flag = 5;
                }
            } else {
                cout << "unknown command" << endl;
                continue;
            }

        }
        if (word[5].find(s1) == 0) {
            if (word[6].find(s2) == 0) {
                if (flag != 0) {
                    cout << "unknown command" << endl;
                    continue;
                } else {
                    flag = 6;
                }
            } else {
                cout << "unknown command" << endl;
                continue;
            }
        }
        if (flag == 0) {
            cout << "unknown command" << endl;
            continue;
        }
        if (flag == 2) {
            cout << "board fault" << endl;
            continue;
        }
        if (flag == 3) {
            cout << "where to add" << endl;
            continue;
        }
        if (flag == 4) {
            cout << "no board at all" << endl;
            continue;
        }
        if (flag == 5) {
            cout << "impossible" << endl;
            continue;
        }
        if (flag == 6) {
            cout << "install first" << endl;
            continue;
        }
    }
}
// 64 位输出请用 printf("%lld")

这题纯傻逼的

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-28 13:48
hory权:校招vip纯神人了,还说自己是什么师范大学的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务