https://www.acmicpc.net/problem/18258
18258번: 큐 2
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 2,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
# 18258 - Python 3
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
arr = []
s = deque()
for i in range(n):
arr = input().split()
if "push" in arr[0:4]:
s.append(arr[-1])
elif "pop" in arr[0:3]:
if s:
a = s.popleft()
print(a)
else:
print("-1")
elif "size" in arr[0:4]:
print(len(s))
elif "empty" in arr[0:5]:
if s:
print("0")
else:
print("1")
elif "front" in arr[0:5]:
if s:
print(s[0])
else:
print("-1")
elif "back" in arr[0:4]:
if s:
print(s[-1])
else:
print("-1")'코딩' 카테고리의 다른 글
| [Python] 백준 #10828. 스택 (0) | 2023.03.29 |
|---|---|
| [Python] 백준 #10845. 큐 (0) | 2023.03.29 |
| [Python] 백준 #10866. 덱 (0) | 2023.03.29 |
| [Python] 백준 #2164. 카드2 (0) | 2023.03.29 |
| [Python] 백준 #13909. 창문 닫기 (0) | 2023.03.29 |