题解 | #配置文件恢复#

# 命   令	执   行
# 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 comma
all_in = ['reset board', 'board add', 'board delete', 'reboot backplane', 'backplane abort']
all_out = ['board fault', 'where to add', 'no board at all', 'impossible', 'install first']
while True:
    try:
        s = input().strip().split()
        l = len(s)
        if l == 1:
            if 'reset'.startswith(s[0]):
                print('reset what')
            else:
                print('unknown command')
        elif l == 2:
            flag = []  # 记录匹配到的命令在all_in中的索引,且当仅当len(flag)==1时,输出相应all_out下标的输出值
            for i in all_in:
                j = i.split()
                if j[0].startswith(s[0]) and j[1].startswith(s[1]):
                    flag.append(all_in.index(i))
            if len(flag) == 1:
                print(all_out[flag[0]])
            else:
                print('unknown command')
        else:
            print('unknown command')               
    except:
        break
全部评论

相关推荐

听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务