题解 | #配置文件恢复#

配置文件恢复

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
全部评论

相关推荐

点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-25 18:29
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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