题解 | #配置文件恢复#

配置文件恢复

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

while True:
    try:
        commond = {
            "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",
            "he he": "unknown command",
        }
        kv = []
        string = input().split()
        if len(string) == 1:
            if len(string[0]) == 1 and string[0] == "r":
                print("reset what")
            elif len(string[0]) > 1 and (
                string[0] == "res" or string[0] == "rese" or string[0] == "reset"
            ):
                print("reset what")
            else:
                print("unknown command")

        elif len(string) == 2:
            for i in commond:
                k = i.split()
                p = i.find(" ")
                if (
                    string[0][: len(string[0])] in k[0][: len(string[0])]
                    and p != -1
                    and string[1][: len(string[1])] in i[p + 1 : p + 1 + len(string[1])]
                ):
                    kv.append(commond[i])

            if len(kv) == 1:
                print(kv[0])
            else:
                print("unknown command")

    except:
        break

全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务