-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.py
More file actions
51 lines (37 loc) · 831 Bytes
/
10828.py
File metadata and controls
51 lines (37 loc) · 831 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
45
46
47
48
49
50
51
import sys
item = int(sys.stdin.readline())
def push(x, lst):
lst.append(x)
def pop(lst):
if len(lst) == 0:
return -1
else:
idx = len(lst)-1
num = lst[idx]
del lst[idx]
return num
def size(lst):
return len(lst)
def empty(lst):
if len(lst) == 0:
return 1
else:
return 0
def top(lst):
if len(lst) == 0:
return -1
else:
return lst[len(lst)-1]
lst = []
for _ in range(item):
com = sys.stdin.readline().strip("\n")
if "push" in com:
push(int(com[5:]), lst)
elif com == "pop":
print(pop(lst))
elif com == "size":
print(size(lst))
elif com == "empty":
print(empty(lst))
elif com == "top":
print(top(lst))