题解 | #配置文件恢复#

配置文件恢复

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

import sys
from collections import OrderedDict
com1 = OrderedDict()
com1['reset board'] = 'board fault'
com1['board add'] = 'where to add'
com1['board delete'] = 'no board at all'
com1['reboot backplane'] = 'impossible'
com1['backplane abort'] = 'install first'
for line in sys.stdin:
    a = line.strip().split()
    if len(a) == 1 and a[0].startswith('r') and a[0] in 'reset':
        print('reset what')
    elif len(a) == 1:
        print('unknown command')
    else:
        save = []
        for i in com1.keys():
            s1,s2 = i.split()
            if s1.find(a[0])==0 and s2.find(a[1])==0:
                save.append(i)
            else:
                continue
        if len(save) == 1:
            print(com1[save[0]])
        else:
            print('unknown command')

全部评论

相关推荐

05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务