题解 | #配置文件恢复#

配置文件恢复

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

import sys,re
tablelist = [['reset'],['reset','board'],['board','add'],['board','delete'],['reboot','backplane'],['backplane','abort']]
table1 = {'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'}
for line in sys.stdin:
    a = line.strip().split(" ")
    resault = []
    for i in tablelist:
        if len(i) == len(a) == 1:
            if re.search(f'^{a[0]}',i[0]):
                resault.append(table1[i[0]])
        elif len(i) == len(a) == 2:
            if re.search(f'^{a[0]}',i[0]) and re.search(f'^{a[1]}',i[1]):
                tamp = i[0]+' '+i[1]
                resault.append(table1[tamp])
    if len(resault) == 1:
        print(resault[0])
    else:
        print('unknown command')

全部评论

相关推荐

08-22 10:08
中南大学 营销
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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