极度不优雅
配置文件恢复
http://www.nowcoder.com/questionTerminal/ca6ac6ef9538419abf6f883f7d6f6ee5
import sys
list1 = []
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'
}
while True:
a = sys.stdin.readline().strip()
if a == '':
break
list1.append(a)
for i in list1:
j = i.split(' ')
if len(j) < 1 or len(j) > 2:
print('unkonwn command')
if len(j) == 1:
if j[0] == ['reset'][0][:len(j[0])]:
print('reset what')
else:
print('unknown command')
elif len(j) == 2:
list2 = []
for key, value in dic.items():
m = key.split(' ')
if j[0] == m[0][:len(j[0])] and j[1] == m[1][:len(j[1])]:
list2.append(value)
if len(list2) == 1:
print(list2[0])
else:
print('unknown command')
查看18道真题和解析