๋ฌธ์ : https://www.acmicpc.net/problem/18258
๋ฌธ์ ํ์ด
import sys
from collections import deque
n = int(input())
queue = deque([])
for i in range(n):
str = sys.stdin.readline()
strArray = str.split()
command = strArray[0]
if len(strArray) > 1:
args = strArray[1]
if (command == 'push') :
queue.append(args)
elif (command == 'pop') :
if not queue:
print(-1)
else:
print(queue.popleft())
elif (command == 'size') :
print(len(queue))
elif (command == 'empty') :
if not queue:
print(1)
else:
print(0)
elif (command == 'front') :
if not queue:
print(-1)
else:
print(queue[0])
elif (command == 'back') :
if not queue:
print(-1)
else:
print(queue[-1])
https://zetawiki.com/wiki/Python_deque_%ED%81%90
๋ฐ์ํ
'๐ค ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
baekjoon. ์นด๋2 [python] [Silver IV] (0) | 2023.03.23 |
---|---|
baekjoon. ํฌ๊ฒ ๋ง๋ค๊ธฐ (2812) [python][Gold III] (0) | 2023.02.22 |
baekjoon. ์ ๋ง๋๊ธฐ (10799) [python][Silver II] (0) | 2023.01.29 |
baekjoon. ์คํ (10828) [python][Silver IV] (0) | 2023.01.16 |
baekjoon. ํ์ ์ด๋ฐฅ (2531) | hashmap์ฌ์ฉ [java] (0) | 2022.10.17 |