blob: 94f417f36b9debf77b1769c96bb2caff4f12541a (
plain)
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
|
import fileinput
stack = []
error = "Stack is empty"
for line in fileinput . input ():
chunks = line . split ()
command = chunks [0]
if command == "push":
stack . append (int (chunks [1]))
if command == "pop":
if len (stack):
stack . pop ()
if command == "top":
if len (stack):
print stack [len (stack) - 1]
else:
print error
if command == "min":
if len (stack):
print min (stack)
else:
print error
|