题解 | #配置文件恢复#

配置文件恢复

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

#使用正则表达式匹配,思路非常简单,命令分单字符串、双字符串和其他字符串,分别考虑就行

import re
min_zx = {"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",}

def is_ok(strr):
    b, outt, flagg, m_l =None, "", 0, strr.split(" ") #定义输出的内容、匹配多个的标签、输入命令转化为列表
    if len(m_l) == 1:
        b = re.compile("^{}[a-z]*$".format(strr))
    elif len(m_l) == 2:
        b = re.compile(r"^{}[a-z]*\s{}[a-z]*$".format(m_l[0],m_l[1]))
    if b:
        for i in min_zx.keys():
            if b.match(i):
                outt = min_zx[i]
                flagg += 1
        if flagg == 1:
            return outt
        else:
            return "unknown command"
    return "unknown command"
while True:
    try:
        a = input()
    except:
        break
    else:
        print(is_ok(a))
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
吴offer选手:HR:我KPI到手了就行,合不合适关我什么事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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