题解 | 配置文件恢复

配置文件恢复

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

import re


while True:
    try:
        std = {("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"}
        s = input().split()
        if len(s) > 2:
            print("unknown command")
        else:
            res = {}
            if len(s) == 1:
                for k, v in std.items():
                    if len(k) == 1:
                        if re.match(s[0], k[0]):
                            res[k] = v
            else:
                for k, v in std.items():
                    if len(k) == 2:
                        if re.match(s[0], k[0]) and re.match(s[1], k[1]):
                            res[k] = v
            if len(res) == 1:
                print(list(res.values())[0])
            else:
                print("unknown command")
    except:
        break

全部评论

相关推荐

05-26 16:13
门头沟学院 C++
牢大肘击Java:海投就完事了bro,就当刷视频了
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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