题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
# 自己写来用于保存的 所以没写注释 能看懂就将就看一下 如果反馈多就重新上传注释版 import re string = r'reset;reset board;board add;board delete;reboot backplane;backplane abort;' mingling = ['reset','reset board','board add','board delete','reboot backplane','backplane abort'] zhixing = ['reset what','board fault','where to add','no board at all','impossible','install first','unknown command'] while True: try: In = input().strip().lower().split(' ') result = zhixing[-1] pattern = r'' if 0 < len(In) <= 2: for s in In: pattern += s + r'[a-z]*?' + ' ' pattern = pattern.strip() + r';' lsts = re.findall(pattern, string) lst = [] if lsts: for l in lsts: if l.replace(';','') in mingling: lst.append(l.replace(';','')) if len(lst) == 1: result = zhixing[mingling.index(lst[0])] print(result) except: break