题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
import re dic = { ("reset", "board"): "board fault", ("board", "add"): "where to add", ("board", "delete"): "no board at all", ("reboot", "backplane"): "impossible", ("backplane", "abort"): "install first", } keys = dic.keys() while True: try: l = input().split() if len(l) == 1: if re.match(l[0], "reset"): print("reset what") else: print("unknown command") elif len(l) == 2: count = 0 ml = "" for x in keys: if re.match(l[0], x[0]) and re.match(l[1], x[1]): count += 1 ml = dic[x] if count == 1: print(ml) else: print("unknown command") except: break