문제 : https://www.acmicpc.net/problem/10845
import sys
input = lambda : sys.stdin.readline().strip()
class Queue(object):
def __init__(self):
self.dts = []
self.lvl = 0
def push(self, x):
self.dts = [x] + self.dts
self.lvl += 1
def pop(self):
if self.lvl == 0: return -1
tmp = self.dts[-1]
self.dts = self.dts[:-1]
self.lvl -= 1
return tmp
def size(self):
return self.lvl
def empty(self):
return 0 if self.dts else 1
def front(self):
if self.lvl == 0: return -1
return self.dts[-1]
def back(self):
if self.lvl == 0: return -1
return self.dts[0]
queue = Queue()
for _ in range(int(input())):
order = input().split()
if order[0] == 'push':
queue.push(order[1])
elif order[0] == 'pop':
print(queue.pop())
elif order[0] == 'size':
print(queue.size())
elif order[0] == 'empty':
print(queue.empty())
elif order[0] == 'front':
print(queue.front())
elif order[0] == 'back':
print(queue.back())