题目描述
有一横排车位,有至少一个车位停了车,也至少有一个车位没停车。一个车位有车用1表示,无车用0表示。为了避免剐蹭,请为司机规划停在哪个车位,距离其他车中间间隔的车位最远。
输入
输入描述:
一组数据,代表目前车位的状态。
输出
输出描述:
当前车辆停车距离其他车辆的最大间距。
示例
输入:1 0 0 0 0 1 0 1 0
输出:3
新来的车停在 下标为1或者小标为4的位置,才会出现距离其他车辆最大距离3
参考代码
def calc():
nums_input = input().split()
max_ = 0
i = 0
j = 1
while j < len(nums_input):
if nums_input[i] == nums_input[j] == "0":
j += 1
else:
max_ = max([max_, j - i])
i = j
j = j + 1
else:
max_ = max([max_, j - i])
print(max_ - 1)
while True:
try:
calc()
except:
break