-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path덱.py
80 lines (57 loc) · 1.13 KB
/
덱.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
from collections import deque
input = sys.stdin.readline
q = deque()
def push_front(q, i):
q.appendleft(i)
def push_back(q, i):
q.append(i)
def pop_front(q):
if len(q) > 0:
print(q[0])
q.popleft()
else:
print("-1")
def pop_back(q):
if len(q) > 0:
print(q[-1])
q.pop()
else:
print("-1")
def size(q):
print(len(q))
def empty(q):
if len(q) == 0:
print("1")
else:
print("0")
def front(q):
if len(q) > 0:
print(q[0])
else:
print("-1")
def back(q):
if len(q) > 0:
print(q[-1])
else:
print("-1")
n = int(input().strip())
for _ in range(n):
command = list(input().split())
command_0 = command[0]
if command_0 == "push_front":
push_front(q, command[1])
if command_0 == "push_back":
push_back(q, command[1])
if command_0 == "pop_front":
pop_front(q)
if command_0 == "pop_back":
pop_back(q)
if command_0 == "size":
size(q)
if command_0 == "empty":
empty(q)
if command_0 == "front":
front(q)
if command_0 == "back":
back(q)