-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10866.py
More file actions
44 lines (38 loc) · 1017 Bytes
/
10866.py
File metadata and controls
44 lines (38 loc) · 1017 Bytes
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
# 덱: 스택,큐 합친거
# 앞뒤로 가능
import sys
item = int(sys.stdin.readline())
lst = []
for _ in range(item):
command = sys.stdin.readline().strip("\n")
if command[:10] == "push_front":
lst.insert(0, int(command[10:]))
elif command[:9] == "push_back":
lst.append(int(command[9:]))
elif command == "pop_front":
if len(lst) == 0:
print(-1)
else:
print(lst.pop(0))
elif command == "pop_back":
if len(lst) == 0:
print(-1)
else:
print(lst.pop())
elif command == "size":
print(len(lst))
elif command == "empty":
if len(lst) == 0:
print(1)
else:
print(0)
elif command == "front":
if len(lst) == 0:
print(-1)
else:
print(lst[0])
elif command == "back":
if len(lst) == 0:
print(-1)
else:
print(lst[-1])