-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.py
More file actions
60 lines (38 loc) · 1.01 KB
/
10828.py
File metadata and controls
60 lines (38 loc) · 1.01 KB
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
import sys
fast_input = sys.stdin.readline
N = int(fast_input())
class Stack:
def __init__(self) -> None:
self.stack = []
def push(self, val):
self.stack.append(val)
def pop(self):
if len(self.stack) >= 1:
print(self.stack.pop())
else:
print(-1)
def size(self):
print(len(self.stack))
def empty(self):
print(int(len(self.stack) == 0))
def top(self):
if len(self.stack) == 0:
print(-1)
else:
print(self.stack[len(self.stack) - 1])
def operation(self, type: str, val=""):
if type == "push":
return getattr(self, type)(val)
return getattr(self, type)()
stack = Stack()
for _ in range(N):
inputs = list(fast_input().split())
method = inputs[0]
num = 0
if len(inputs) > 1:
method = inputs[0]
num = int(inputs[1])
if method == "push":
stack.operation("push", num)
continue
stack.operation(method)