题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
dic = { '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' } key = list(dic.keys()) value = list(dic.values()) while True: try: pass line = input() cmd = line.split() if len(cmd) != 1 and len(cmd) != 2: print('unknown command') continue if len(cmd) == 1: if 'reset'.startswith(cmd[0]): print(dic[key[0]]) continue else: print('unknown command') continue tmp = [] for k in key[1:]: kk = k.split() if kk[0].startswith(cmd[0]) and kk[1].startswith(cmd[1]): tmp.append(k) if len(tmp) != 1: # 可以把满足条件的都记录下来,然后再判断是否唯一 print('unknown command') continue else: print(dic[tmp[0]]) continue except EOFError: break