请完善程序:
def inputStack(bh,stacks,n): # 将车厢移到缓冲轨处
global k
bestStack = -1 # bestStack 记录最小车厢编号所在的缓冲轨编号
bestTop = n + 1 # bestTop 记录缓冲轨中的最小车厢编号
for i in range(k):
if len(stacks[i])>0:
top = stacks[i][-1]
if ________________________ : #填空1
bestTop = top
bestStack = i
else:
if bestStack == -1:
bestStack = i
if bestStack == -1:
return False
stacks[bestStack].append(bh)
print('Move carriage %d from the track entry point to the buffer track H%d.' % ( bh, bestStack+1 ) )
def output( stacks, n ):
# 将缓冲轨中的剩余车厢按顺序依次移到出轨处
while True:
minNum = n + 1
for j in range(k):
if len(hStacks[j]) > 0:
if hStacks[j][-1] < minNum:
minNum = hStacks[j][-1]
minStack=j
if minNum == n + 1:
break
print("Move carriage %d from buffer track H%d to the derailment point." % ( minNum, minStack+1 ) )
hStacks[minStack].pop()
# 主程序开始
list1 = list( map( int, input().split(' ') ) )
n = len( list1 )
k = int( input() )
hStacks = [ __________ for i in range(k) ] #填空2
curBH = 1
minStack = -1
print("The process of car rearrangement is as follows:")
i = 0
while i < n:
if list1[i] == curBH:
print("Move carriage %d directly from the track entry point to the derailment point." % list1[i])
______________________ #填空3
i += 1
_____________________ #填空4
while True:
minNum = n + 1
for j in range(k):
if len( hStacks[j] ) > 0:
if hStacks[j][-1] < minNum:
minNum = hStacks[j][-1]
minStack=j
if minNum == curBH:
print( "Move carriage %d from buffer track H%d to the derailment point." % ( minNum, minStack+1 ) )
hStacks[ minStack ].pop()
_______________________ #填空5
else:
___________________________ #填空6
i += 1; break
while curBH < n+1:
output( hStacks, n ); curBH += 1
print( "Complete carriage rearrangement!" )