电梯响应优先次序
两部电梯分别是左梯:left,右梯:right,你所在的楼层:call,你按下按钮后离你最近的电梯
优先响应。
实例:
输入:3,6,4
输出:'step left' #左边的电梯优先响应
import random
left,right,call= 6,2,4
def elevator(left,right,call):
if abs(call-left) > abs(call-right):
right = call
return 'step right'
elif abs(call-left) < abs(call-right):
left = call
return 'step left'
elif abs(call-left) == abs(call-right):
return 'step ' + random.choice(['left','right'])
网友评论