题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
import sys for line in sys.stdin: cmds = line.strip().split() cmd_set = ['reset', 'reset board', 'board add', 'board delete', 'reboot backplane', 'backplane abort', 'he he'] ops = ['reset what', 'board fault', 'where to add', 'no board at all', 'impossible', 'install first', 'unknown command'] flg = 0 if len(cmds) == 1: if cmd_set[0].startswith(cmds[0]): print(ops[0]) else: print(ops[-1]) else: for i in range(1, len(cmd_set)): tmp_cmd = cmd_set[i].split() if tmp_cmd[0].startswith(cmds[0]) and tmp_cmd[1].startswith(cmds[1]): #保存操作 OPS=ops[i] flg += 1 # break #唯一匹配才操作成功,否则'unknown command' if flg == 1: print(OPS) else: print(ops[-1])