题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
while True:
try:
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'
}
command = input().strip()
command_list = command.split(' ')
length = len(command_list)
result_list = []
for key, value in d.items():
key_list = key.split(' ')
len_key = len(key_list)
if length==1 and len_key == 1:
if key.startswith(command_list[0]):
# 匹配上
result_list.append(value)
if length==2 and len_key == 2:
if key_list[0].startswith(command_list[0]) and key_list[1].startswith(command_list[1]):
result_list.append(value)
if len(result_list)==1:
print(result_list[0])
else:#没有匹配上或者匹配到多个
print('unknown command')
except:
break
查看8道真题和解析