Programming/Python & Data Structures
[Baekjoon/Python3] 10845번 큐
HooNeee
2020. 12. 8. 21:47
[Baekjoon/Python3] 10845번 큐
10845번: 큐
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
import sys
q = []
for i in range(int(sys.stdin.readline())):
s = sys.stdin.readline().split()
if s[0] == 'push':
q.append(s[1])
elif s[0] == 'pop':
print(q.pop(0) if q else -1)
elif s[0] == 'size':
print(len(q))
elif s[0] == 'empty':
print(0 if q else 1)
elif s[0] == 'front':
print(q[0] if q else -1)
elif s[0] == 'back':
print(q[-1] if q else -1)