题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#存储配置命令(1串和2串分开) # dic1={'reset':'reset what'}# 只有一个也可以不用字典,直接写 dic2={'reset board':'board fault','board add':'where to add', 'board delete':'no board at all','reboot backplane':'impossible','backplane abort':'install first'} while 1: try: str_list=list(map(str,input().split('\n'))) for i in str_list: if ' ' not in i:#不含空格,直接匹配dic1:reset if i == 'reset'[:len(i)]: print('reset what') else: print('unknown command') else:#含空格,按空格分割,进行匹配 str_l=i.split(' ') ans=[] a,b='','' for k in dic2: a,b=k.split(' ') if str_l[0]==a[:len(str_l[0])]: if str_l[1] == b[:len(str_l[1])]: ans.append(k) if len(ans)==1: print(dic2[ans[0]]) else: print('unknown command') except: break