题解 | 配置文件恢复

dic = {
    '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',
    'he he':'unknown command'
}

comds = [
    'reset' ,
    'reset board',
    'board add',
    'board delete',
    'reboot backplane',
    'backplane abort',
    'he he'
]

def check(s,comds):
    count = 0
    rets = ''
    ins = s.split()
    for cm in comds:
        cmd = cm.split()
        if len(cmd) == len(ins):
            check_keyword = False
            for i in range(len(cmd)):
                if not ins[i] == cmd[i][:len(ins[i])] :
                    check_keyword = False
                    break
                # print('is ? ',ins[i] , cmd[i][:len(ins[i])])
                check_keyword = True
            if check_keyword :
                rets = cm
                count = count + 1
    # print('count',count)
    return count == 1 , rets

try:
    while True:
        s = input()
        check_result = check(s,comds)
        if check_result[0] == True :
            print(dic[check_result[1]])
        else:
            print("unknown command")
        pass

except :
    pass




全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务