laughs停车场有一条单行道,最多可容纳10辆车。汽车到达车库的南端,从北端离开。如果顾客来取车 那不是最北的,他车北边的所有车都搬走了,他的车也开出去了, 其他的车都恢复了原来的顺序。 每当一辆汽车离开时,所有往南的汽车都向前移动。所以 所有的空位都在车库的南部。 编写python程序来读取一组输入行。每行包含一个“a”到达或 “d”字头和车牌号码。假定车辆按顺序到达和离开 由输入指定。程序应该在每次汽车到达或 离开。当一辆车到达时,按摩师应说明是否有车的空间 在车库里。如果没有车位,车辆会一直等到有空位或发车线 为汽车读书。当有空房间时,应打印另一份按摩。当一辆车 离开时,按摩应包括汽车在车库内移动的次数 (包括出发时间,但不包括到达时间),如果车辆离开 排队等候。在
这是我的密码。我卡在代码的中间。我排队停车。我不知道当一辆中间的车离开时如何重新组装汽车。我想要一种方法,在汽车离开停车场之前打印出移动的次数。有人能帮我吗?`在
class Stack:
def __init__(self):
self.items =[]
def isEmpty(self):
return self.items ==[]
def push(self,item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items)-1]
def size(self):
return len(self.items)
class Queue:
def __init__(self,maxSize):
self.items =[]
self._count = 0
self._front = 0
self._back = maxSize - 1
def isEmpty(self):
return self.items ==[]
def enqueue(self, item):
self.items.insert(0,item)
def dequeue(self):
return self.items.pop()
def size(self):
return len(self.items)
def index(self,item):
return self.items.index(item)
q1park = Queue(maxSize=10)
q2wait= Queue()
q3assemble= Queue()
x =raw_input("Car number: ")
def cararrival():
if x[0]=="a":
while q1park.size ==10:
q1park.enqueue(x[1:len(x)])
print(x + "car is arrived")
if q1park.size ==10:
print("No room available in the garage")
x1=raw_input("do you want to wait: ")
if x1=="yes":
q2wait.enqueue(x[1:len(x)])
elif x1=="no":
print("see you next time")
else:
print("Enter yes or no")
def cardepart():
if x[0]=="d":
if x[1:len(x)] in q1park:
while not q1park.index(x[1:len(x)])==0:
q3assemble.enqueue(q1park.dequeue())
q3assemble.dequeue()
while not q3assemble.isEmpty:
以上问题我的答案在这里。在
相关问题 更多 >
编程相关推荐