题解 | #配置文件恢复# 为方便使用startswith

配置文件恢复

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

one = "reset"
two1 = ["reset", "board", "board", "reboot", "backplane"]
two2 = ["board", "add", "delete", "backplane", "abort"]
fail = "unknown command"
r = "reset what"
a = ["board fault", "where to add", "no board at all", "impossible", "install first"]

while True:
    try:
        string = input().split(" ")
        if string in [["b", "a"], ["r", "b"]] or not string[0]:
            print(fail)
        else:
            if len(string) == 1:
                if one.startswith(string[0]):
                    print(r)
                else:
                    print(fail)
            elif len(string) == 2:
                if not string[1]:
                    print(fail)
                    continue
                for i in range(5):
                    if two1[i].startswith(string[0]) and two2[i].startswith(string[1]):
                        print(a[i])
                        break
                else:
                    print(fail)
            else:
                print(fail)
    except:
        break

#刷题#
全部评论

相关推荐

qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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