题解 | 配置文件恢复

配置文件恢复

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

import sys
def isok(s,t):
    if len(s) > len(t):
        return False
    for i in range(len(s)):
        if s[i] != t[i]:
            return False
    return True
while True:
    try:
        comd = input().split()
        bod ={
            ('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'
        }
        pipei = []
        for c in bod.keys():
            if len(comd) == len(c):
                for i in range(len(comd)):
                    if not isok(comd[i],c[i]):
                        break
                else:
                    pipei.append(bod[c])
        if not pipei or len(pipei) > 1:
            print('unknown command')
        else:
            print(pipei[0])
    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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