-
Notifications
You must be signed in to change notification settings - Fork 0
/
10828.py
54 lines (39 loc) · 767 Bytes
/
10828.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
import sys
stack = []
total = 0
def push(n):
stack.append(n)
def pop():
if total == 0:
print(-1)
else:
print(stack[total - 1])
del stack[total - 1]
def size():
print(total)
def empty():
if total == 0:
print(1)
else:
print(0)
def top():
if total == 0:
print(-1)
else:
print(stack[total-1])
num = int(sys.stdin.readline().rstrip())
for _ in range(num):
order = sys.stdin.readline().rstrip()
if order == 'pop':
pop()
if total != 0:
total -= 1
elif order == 'size':
size()
elif order == 'empty':
empty()
elif order == 'top':
top()
else:
total += 1
push(int(order.split()[1]))