题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
import sys import re getline=lambda:sys.stdin.readline().strip() line=getline() d={'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'} while line: if len(line.split(" ")) == 1: n=0 for k in d.keys(): if re.match("^%s.*"%line, k): if (len(k.split(' ')))==1: print(d[k]) n=n+1 if n==0: print("unknown command") else: n=0 for k in d.keys(): if re.match("^%s.*%s.*"%(line.split(" ")[0],line.split(" ")[1]), k): if (len(k.split(' ')))==2: print(d[k]) n=n+1 if n==0: print("unknown command") line=getline()