https://www.acmicpc.net/problem/10828
10828번: 스택
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
# 10828 - 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:
s.appendleft(arr[-1])
elif "pop" in arr:
if s:
a = s.popleft()
print(a)
else:
print("-1")
elif "size" in arr:
print(len(s))
elif "empty" in arr:
if s:
print("0")
else:
print("1")
elif "top" in arr:
if s:
print(s[0])
else:
print("-1")'코딩' 카테고리의 다른 글
| [Python] 백준 #1966. 프린터 큐 (0) | 2023.03.29 |
|---|---|
| [Python] 백준 #10773. 제로 (0) | 2023.03.29 |
| [Python] 백준 #10845. 큐 (0) | 2023.03.29 |
| [Python] 백준 #18258. 큐 2 (0) | 2023.03.29 |
| [Python] 백준 #10866. 덱 (0) | 2023.03.29 |