-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_10828.py
More file actions
34 lines (30 loc) · 743 Bytes
/
Copy pathbj_10828.py
File metadata and controls
34 lines (30 loc) · 743 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
import sys
from collections import deque
# sys.stdin = open("bj_10828_in.txt", 'r')
# input = sys.stdin.readline
def input():
return sys.stdin.readline().rstrip()
stack = deque()
N = int(input())
for _ in range(N):
command = input().split()
if command[0] == 'push':
stack.append(command[1])
elif command[0] == 'top':
if stack:
print(stack[-1])
else:
print(-1)
elif command[0] == 'size':
print(len(stack))
elif command[0] == 'empty':
if stack:
print(0)
else:
print(1)
elif command[0] == 'pop':
if stack:
print(stack.pop())
else:
print(-1)
# print(input().strip().split())