1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import sys
from collections import deque
n = int(input())
dq = deque([])
for i in range(n):
command = list(map(str,sys.stdin.readline().split()))
if command[0] == "push_front":
dq.appendleft(command[1])
elif command[0] == "push_back":
dq.append(command[1])
elif command[0] == "pop_front":
if not dq:
print(-1)
else:
print(dq.popleft())
elif command[0] == "pop_back":
if not dq:
print(-1)
else:
print(dq.pop())
elif command[0] == "size":
print(len(dq))
elif command[0] == "empty":
if not dq:
print(1)
else:
print(0)
elif command[0] == "front":
if not dq:
print(-1)
else:
print(dq[0])
elif command[0] == "back":
if not dq:
print(-1)
else:
print(dq[-1])
|
cs |
'백준' 카테고리의 다른 글
백준 10828번: 스택 (0) | 2021.09.30 |
---|---|
백준 10845번: 큐 (0) | 2021.09.30 |
백준 1920번: 수 찾기 (0) | 2021.09.29 |
백준 10989번: 수 정렬하기 3 (0) | 2021.09.29 |
백준 2231번: 분해합 (0) | 2021.09.29 |