题解 | #配置文件恢复#

配置文件恢复

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

# 2024年10月31日   周四  上午10:31

ke = [
    "reset",
    "reset board",
    "board add",
    "board delete",
    "reboot backplane",
    "backplane abort",
]
va = [
    "reset what",
    "board fault",
    "where to add",
    "no board at all",
    "impossible",
    "install first",
]
while True:
    try:
        s = input().split()
        if len(s) < 0 or len(s) >= 3:
            print("unknown command")
        elif len(s) == 1:
            if s[0] == ke[0][: len(s[0])]:
                print(va[0])
            else:
                print("unknown command")
        elif len(s) == 2:
            ls = []
            for i in range(1, len(ke)):  # 假如 i = 'reset board'
                a = ke[i].split()  #'reset board',其中a[0]='reset', a[1]='board'
                if s[0] == a[0][: len(s[0])] and s[1] == a[1][: len(s[1])]:
                    ls.append(i)
            if len(ls) == 1:
                print(va[ls[0]])
            else:
                print("unknown command")

    except:
        break

全部评论

相关推荐

10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务