题解 | #配置文件恢复#
配置文件恢复
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))