题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
cmds = {
('reset', 'board') : 'board fault',
('board', 'add') : 'where to add',
('board', 'delete') : 'no board at all',
('reboot', 'backplane') : 'impossible',
('backplane', 'abort') : 'install first'
}
while True:
try:
words = input().split(' ')
if len(words) == 1:
if words[0]:
if words[0] == 'reset'[:len(words[0])]:
print('reset what')
else:
print('unknown command')
elif len(words) == 2:
matched = []
for pair in cmds:
if words[0] == pair[0][:len(words[0])] and words[1] in pair[1][:len(words[1])]:
matched.append(pair)
if len(matched) == 1:
print(cmds[matched[0]])
else:
print('unknown command')
except:
break