-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10866.py
More file actions
51 lines (40 loc) · 1.68 KB
/
10866.py
File metadata and controls
51 lines (40 loc) · 1.68 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
input = sys.stdin.readline
n = int(input())
deque = [] # 리스트로 덱 만듬
for i in range(n):
command = []
command = input().split() # 명령어 입력 받음
if command[0] == 'push_front': # push_front 일 때
deque.insert(0, int(command[1])) # 덱의 앞에 정수 저장
elif command[0] == 'push_back': # push_back 일 때
deque.append(int(command[1])) # 덱의 뒤에 정수 저장
elif command[0] == 'pop_front': # pop_front 일 때
if len(deque) == 0: # 비어있으면 -1 출력
print(-1)
else:
print(deque[0]) # 맨 앞에 있는 정수 출력 후
del deque[0] # 맨 앞에 있는 정수 제거
elif command[0] == 'pop_back': # pop_back 일 때
if len(deque) == 0: # 비어있으면 -1 출력
print(-1)
else:
print(deque[-1]) # 맨 뒤에 있는 정수 출력 후
del deque[-1] # 맨 뒤에 있는 정수 제거
elif command[0] == 'front': # front 일 때
if len(deque) == 0:
print(-1)
else:
print(deque[0]) # 맨 앞에 있는 정수 출력
elif command[0] == 'back': # back 일 때
if len(deque) == 0:
print(-1)
else:
print(deque[-1]) # 맨 뒤에 있는 정수 출력
elif command[0] == 'size': # size 일 때
print(len(deque)) # 스택의 크기 출력
elif command[0] == 'empty': # empty 일 때
if len(deque) == 0: # 비어있으면 1 출력
print(1)
else: # 안 비어있으면 0 출력
print(0)