题解 | #配置文件恢复#

配置文件恢复

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
02-16 22:33
杉川机器人 嵌入式工程师 18.0k*13.0, 年终奖1~9个月浮动
点赞 评论 收藏
分享
01-02 00:50
三峡大学 Java
程序员牛肉:这简历一出手就离失业不远了。 作为一家公司来讲,我如果要招日常实习生,那我对实习生最基本的要求就是要能干活,毕竟你就待三四个月,谁会留心培养你? 那么除了院校之外,最重要的就是项目和实习了。没有实习的话项目就好好搞。 但是你说你这个项目吧:课程作业管理系统和TMS运输管理系统。这两个基本就和闹着玩差不多。 你作为一个想要应聘Java开发实习生的人,对后端的理解还仅仅停留在:“使用mapper和sql映射”,“使用SQL进行多表调用”,“基于MySQL简历表结构”,“基于Spring boot完成CURD操作”这种玩具上......... 找不到后端实习的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务