题解 | #【模板】队列#
【模板】队列
https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549
import sys # for line in sys.stdin: # a = line.split() # print(int(a[0]) + int(a[1])) class Myqueue: def __init__(self ): pass self.queue=[] def push(self,x): self.queue.append(x) #Pop函数这里出对的时候取对首元素 def pop(self): x =self.queue[0] self.queue.remove(x) return x def front(self): x =self.queue[0] #self.queue.remove(x) return x opration=[] n=int(input()) while n > 0: s = input() opration.append(s) n -= 1 queue=Myqueue() for x in opration: if x[0:4] == "push": number = int(x[4:]) queue.push(number) elif x == "pop": try: print(queue.pop()) except: print("error") elif x == "front": try: print(queue.front()) except: print("error")