백준
10866 덱
판다꼬마
2022. 5. 1. 23:27
728x90
https://www.acmicpc.net/problem/10866
내 풀이
from collections import deque
import sys
d = deque()
n = int(input())
for i in range(n):
command = sys.stdin.readline().split()
if command[0] == "push_front":
d.appendleft(command[1])
elif command[0] == "push_back":
d.append(command[1])
elif command[0] == "pop_front":
if d:
print(d[0])
d.popleft()
else:
print("-1")
elif command[0] == "pop_back":
if d:
print(d[len(d) - 1])
d.pop()
else:
print("-1")
elif command[0] == "size":
print(len(d))
elif command[0] == "empty":
if d:
print("0")
else:
print("1")
elif command[0] == "front":
if d:
print(d[0])
else:
print("-1")
elif command[0] == "back":
if d:
print(d[len(d) - 1])
else:
print("-1")
해결 방법
그냥 덱 구현 방법을 물어보는 문제이다.
728x90