题解 | #配置文件恢复#

配置文件恢复

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

cmds = {
    ('reset', 'board') : 'board fault',
    ('board', 'add') : 'where to add',
    ('board', 'delete') : 'no board at all',
    ('reboot', 'backplane') : 'impossible',
    ('backplane', 'abort') : 'install first'
}
while True:
    try:
        words = input().split(' ')
        if len(words) == 1:
            if words[0]:
                if words[0] == 'reset'[:len(words[0])]:
                    print('reset what')
                else:
                    print('unknown command')
        elif len(words) == 2:
            matched = []
            for pair in cmds:
                if words[0] == pair[0][:len(words[0])] and words[1] in pair[1][:len(words[1])]:
                    matched.append(pair)
            if len(matched) == 1:
                print(cmds[matched[0]])
            else:
                print('unknown command')
    except:
        break
全部评论

相关推荐

10-25 12:05
已编辑
湖南科技大学 Java
若梦难了:我有你这简历,已经大厂乱杀了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务