백준
1.python
정상작동
rom sys import stdin
N = int(stdin.readline())
Que = []
for i in range(N) :
A = stdin.readline().split()
if A[0] == 'push' : Que.append(A[1])
elif A[0] == 'pop' :
if Que : print(Que.pop(0))
else : print(-1)
elif A[0] == 'size' : print(len(Que))
elif A[0] == 'empty' :
if len(Que) == 0 : print(1)
else : print(0)
elif A[0] == 'front' :
if len(Que) == 0 : print(-1)
else : print(Que[0])
elif A[0] == 'back' :
if len(Que) == 0 : print(-1)
else : print(Que[-1])
런타임 에러
import sys
from collections import deque
n = int(sys.stdin.readline())
queue = deque()
for _ in range(n):
command = sys.stdin.readline().split()
if command[0] == 'push':
queue.append(command[1])
elif command[0] == 'pop':
print(queue.popleft())
elif command[0] == 'size':
print(len(queue))
elif command[0] == 'empty':
if len(queue) == 0:
print(1)
else:
print(0)
elif command[0] == 'front':
if queue:
print(queue[0])
else:
print(-1)
elif command[0] == 'back':
if queue:
print(queue[-1])
else:
print(-1)