题解 | 配置文件恢复

# 佩服@中年美少女写的切片思想,学习为敬
while True:
    try:
        m = input().split()
        key = ['reset','reset board','board add','board delete','reboot backplane','backplane abort',]
        value = ['reset what','board fault','where to add','no board at all','impossible','install first']
        if len(m) < 1 or len(m) > 2:
            print('unknown command')
        elif len(m) == 1:  # 根据已知的6条命令,能匹配成功的只有第一条key[0],value[0]
            if m[0] == key[0][:len(m[0])]:
                print(value[0])
            else:
                print('unknown command')
        else:
            index = []
            for i in range(1,len(key)):
                ls = key[i].split()
                if m[0] == ls[0][:len(m[0])] and m[1] == ls[1][:len(m[1])]:
                    index.append(i)
            if len(index) != 1:
                print('unknown command')
            else:
                print(value[index[0]])
    except:
        break

全部评论

相关推荐

字节 测开 25*15
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务