-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.py
44 lines (42 loc) · 1005 Bytes
/
deck.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
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
dq = deque()
for i in range(N):
value = input().rstrip()
if " " in value:
name, num = value.split()
if name == 'push_back':
dq.append(num)
elif name == 'push_front':
dq.appendleft(num)
elif value == 'pop_front':
if len(dq) == 0:
print(-1)
else:
pop = dq.popleft()
print(pop)
elif value == 'pop_back':
if len(dq) == 0:
print(-1)
else:
pop = dq.pop()
print(pop)
elif value == 'size':
print(len(dq))
elif value == 'empty':
if len(dq) == 0:
print(1)
else:
print(0)
elif value == 'front':
if len(dq) == 0:
print(-1)
else:
print(dq[0])
elif value == 'back':
if len(dq) == 0:
print(-1)
else:
print(dq[len(dq)-1])