题解 | #配置文件恢复#

配置文件恢复

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

startswith就够了

import sys

cmd1_dict = {
    "reset":"reset what",
}
cmd2_dict = {
    "reset board":"board fault",
    "board add":"where to add",
    "board delete":"no board at all",
    "reboot backplane":"impossible",
    "backplane abort":'install first'
}

def run(seq: str):
    seq = seq.split()
    res = "unknown command"
    i = 0
    if len(seq)<1:
        return res
    elif len(seq) == 1:
        for k in cmd1_dict.keys():
            if k.startswith(seq[0]):
                res = cmd1_dict[k]
                i+=1
    elif len(seq) == 2:
        for k in cmd2_dict.keys():
            tmp = k.split()
            if tmp[0].startswith(seq[0]) and tmp[1].startswith(seq[1]):
                res = cmd2_dict[k]
                i+=1
    if i > 1:
        res = "unknown command"
    return res

for cmd in sys.stdin:
    cmd = cmd.strip()
    print(run(cmd))
全部评论

相关推荐

风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
07-10 12:17
已编辑
商丘师范学院 Java
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

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