728x90
반응형
SMALL
구현 언어: 파이썬
import sys
input = sys.stdin.readline
n = int(input())
deque = []
for i in range(n):
command = list(input().split())
if command[0] == 'push_front':
deque.insert(0, command[1])
elif command[0] == 'push_back':
deque.append(int(command[1]))
elif command[0] == 'pop_front':
if deque:
print(deque.pop(0))
else:
print(-1)
elif command[0] == 'pop_back':
if deque:
print(deque.pop(len(deque) - 1))
else:
print(-1)
elif command[0] == 'size':
print(len(deque))
elif command[0] == 'empty':
if deque:
print(0)
else:
print(1)
elif command[0] == 'front':
if deque:
print(deque[0])
else:
print(-1)
elif command[0] == 'back':
if deque:
print(deque[-1])
else:
print(-1)
시도 횟수: 1
구현 포인트:
728x90
반응형
LIST
'Archive > BOJ' 카테고리의 다른 글
백준 10816번: 숫자 카드 2 (0) | 2021.02.14 |
---|---|
백준 9012번: 괄호 (0) | 2021.02.14 |
백준 10845번: 큐 (0) | 2021.02.14 |
백준 10828번: 스택 (0) | 2021.02.14 |
백준 11866번: 요세푸스 문제 0 (0) | 2021.02.14 |