Problem:


Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free.

Write a program which reads an expression in the Reverse Polish notation and prints the computational result.

An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.

Input

An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.

You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106

Output

Print the computational result in a line.

Constraints

2 ≤ the number of operands in the expression ≤ 100

1 ≤ the number of operators in the expression ≤ 99

-1 &times; 109 ≤ values in the stack ≤ 109

Sample Input 1

1 2 +

Sample Output 1

3

Sample Input 2

1 2 + 3 4 - *

Sample Output 2

-3

Notes

Template in C



Sample input:
1 2 +


Sample output:
3

Submission status: Accepted

Solution code:
symbol=[x for x in input().split()]
stack=[]

for i in range(len(symbol)):
    if symbol[i]!="+" and symbol[i]!="-" and symbol[i]!="*":
        stack.append(int(symbol[i]))
    elif symbol[i]=="+":
        b=stack.pop()
        a=stack.pop()
        stack.append(a+b)
    elif symbol[i]=="-":
        b=stack.pop()
        a=stack.pop()
        stack.append(a-b)
    elif symbol[i]=="*":
        b=stack.pop()
        a=stack.pop()
        stack.append(a*b)

print(stack.pop())

Submission status: Accepted

Solution code:
S = [s for s in input().split()]
stack = []
for s in S:
    
    if s.isdigit() == True:
        stack.append(s)
    
    elif s == '+' or '-' or '*':
        b=int(stack.pop())
        a=int(stack.pop())
        if s == '+':
            stack.append(a+b)
        elif s == '-':
            stack.append(a-b)
        elif s == '*':
            stack.append(a*b)

print(stack[0])

Submission status: Accepted

Solution code:
s=list(input().split())
A = []

for x in s:
    A.append(x)
    
    if x == '+':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)+int(b))
    elif x == '-':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)-int(b))
    elif x == '*':
        A.pop()
        a,b = A[-2],A[-1]
        A.pop()
        A.pop()
        A.append(int(a)*int(b))
        
print(A[0])

Submission status: Accepted

Solution code:
A = [i for i in input().split()]
S = []

for i in A:
    if i in ['+', '-', '*']:
        b = S.pop()
        a = S.pop()

    if i == '+':
        S.append(a + b)
    elif i == '-':
        S.append(a - b)
    elif i == '*':
        S.append(a * b)
    else:
        S.append(int(i))

print(S.pop())

Submission status: Accepted

Solution code:
import re

def calc(stack, ope):
    symbol = stack.pop()
    if re.match('[0-9]+', symbol):
        b = int(symbol)
    else:
        b = calc(stack, symbol)

    symbol = stack.pop()
    if re.match('[0-9]+', symbol):
        a = int(symbol)
    else:
        a = calc(stack, symbol)

    if ope == '+':
        return a + b
    elif ope == '-':
        return a - b
    elif ope == '*':
        return a * b
    else:
        raise RuntimeException("Unknown operator %s" % ope)

stack = input().split()

print(calc(stack, stack.pop()))

Submission status: Accepted

Solution code:
stack = []
line = list(map(str, input().split()))

for op in line:
    if op in '+-*':
        v2, v1 = stack.pop(), stack.pop()
        stack.append(str(eval(v1 + op + v2)))
    else:
        stack.append(op)
print(stack[0])

Submission status: Accepted

Solution code:
operators = {
	"+": (lambda a, b: a + b),
	"-": (lambda a, b: a - b),
	"*": (lambda a, b: a * b),
	"/": (lambda a, b: a / b)
}

def evaluate(tokens):
	stack = []
	for token in tokens:
		if token in operators:
			arg2 = stack.pop()
			arg1 = stack.pop()
			result = operators[token](arg1, arg2)	
			stack.append(result)
		else:
			stack.append(int(token))
	  
	return stack.pop()
  
expression = input()

tokens = expression.split()

print(evaluate(tokens))

Submission status: Accepted

Solution code:
#Take a dictionary of operators
operators = {
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"/": (lambda a, b: a / b)
}

def evaluate(tokens):
    #Take empty Stack
    stack = []
    
    #Loop through each token
    for token in tokens:
    #If it is a token , then perform operation
        if token in operators:
            # Take the top 2 arguments and perform operation
            arg2 = stack.pop()
            arg1 = stack.pop()
            result = operators[token](arg1, arg2)
            stack.append(result)
        else:
            #Else, append it to the stack
            stack.append(int(token))
    
    return stack.pop()
  
#Read input   
expression = input()

#Split the tokens
tokens = expression.split()

#Print the result
print(evaluate(tokens))

Submission status: Accepted

Solution code:

def pol_calc(symbols):
    stack = []
    for s in symbols:
        if s.isdigit():
            stack.append(int(s))
        elif s == '+':
            y = stack.pop()
            x = stack.pop()
            stack.append(x + y)
        elif s == '-':
            y = stack.pop()
            x = stack.pop()
            stack.append(x - y)
        elif s == '*':
            y = stack.pop()
            x = stack.pop()
            stack.append(x * y)
    return stack.pop()

if __name__ == "__main__":
    symbols = input().split()
    print(pol_calc(symbols))

Submission status: Accepted

Solution code:
n=list(input().split())
stack=[]
for i in n:
    if i not in "+-*":
        stack.append(i)
    else:
        a=stack.pop()
        b=stack.pop()
        stack.append(str(eval(b+i+a)))
print(*stack)

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, value, prev):
        self.value = value
        self.prev = prev


class Stack:
    def __init__(self):
        self.last = None

    def add(self, value):
        next_node = Node(value, self.last)
        self.last = next_node

    def pop(self):
        if not self.last:
            return -1
        v = self.last.value
        self.last = self.last.prev
        return v


stack = Stack()
s = input().split()
for c in s:
    if c in '+-*':
        a = stack.pop()
        b = stack.pop()
        if c == '+':
            stack.add(a + b)
        elif c == '-':
            stack.add(b - a)
        else:
            stack.add(a * b)
    else:
        stack.add(int(c))

print(stack.pop())

Submission status: Accepted

Solution code:
l=list(input().split())
s=[]
for c in l:
#    print(c)
    
    if c=='+':
        b=s.pop()
        a=s.pop()
        s.append(a+b)
    elif c=='-':
        b=s.pop()
        a=s.pop()
        s.append(a-b)
    elif c=='*':
        b=s.pop()
        a=s.pop()
        s.append(a*b)
    else:
        s.append(int(c))
    
#    print(s)

print(s.pop())

Submission status: Accepted

Solution code:
#n = input()
a = list(input().split())
#print(a)
#b = list(map(int, input().split()))
#c = list(map(int, input().split()))
r = int()
stack = []
for i in a:
    if i.isdigit():
        stack.append(int(i))
    elif i == "+": 
        #print(stack)      
        r = stack[-1] + stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "-":
        #print(stack)
        r = stack[-2] - stack[-1]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "*":
        #print(stack)
        r = stack[-1] * stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
print(stack[0])

Submission status: Accepted

Solution code:
from operator import add,sub,mul

formula = input().split()
stack = []
op = {"+":add, "-":sub, "*":mul}

for i in formula:
    if i.isdigit():
        stack.append(int(i))
    else:
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op[i](op1, op2))

print(stack[0])

Submission status: Accepted

Solution code:
stack = []
A = list(input().split())

for i in A:
    if i == "+":
        a = stack.pop()
        b = stack.pop()
        c = b + a
        stack.append(c)
    elif i == "-":
        a = stack.pop()
        b = stack.pop()
        c = b - a
        stack.append(c)
    elif i == "*":
        a = stack.pop()
        b = stack.pop()
        c = b * a
        stack.append(c)
    else:
        stack.append(int(i))

print(stack[0])

Submission status: Accepted

Solution code:
import sys
A = list(map(str,input().split()))
B=[]
for i in range(len(A)):
  c=0
  if A[i].isdecimal():
    B.append(int(A[i]))
  else:
    if A[i]=='+':
      c=B.pop(-2)+B.pop(-1)
      B.append(c)
    elif A[i]=='-':
      c=B.pop(-2)-B.pop(-1)
      B.append(c)
    elif A[i]=='*':
      c=B.pop(-2)*B.pop(-1)
      B.append(c)
print(B[-1])

Submission status: Accepted

Solution code:
from collections import deque
l=deque()
a=list(input().split())
for i in range(len(a)):
    if a[i]=="+":
        b=l.pop()
        c=l.pop()
        l.append(b+c)
    elif a[i]=="-":
        b=l.pop()
        c=l.pop()
        l.append(c-b)
    elif a[i]=="*":
        b=l.pop()
        c=l.pop()
        l.append(b*c)
    else:
        l.append(int(a[i]))

print(l[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    exp = list(map(str, input().split()))
    tmp = []
    for e in exp:
        if e == '+':
            tmp.append(tmp.pop() + tmp.pop())
        elif e == '-':
            tmp.append(-tmp.pop() + tmp.pop())
        elif e == '*':
            tmp.append(tmp.pop()*tmp.pop())
        else:
            tmp.append(int(e))
    print(tmp[0])

Submission status: Accepted

Solution code:
S = input().split()
ope = []

for s in S:
  if s.isdigit():
    ope.append(s)
  else:
    a = int(ope.pop())
    b = int(ope.pop())
    if s == '+':
      ope.append(a + b)
    elif s == '-':
      ope.append(b - a)
    else:
      ope.append(a * b)
print(ope[0])

Submission status: Accepted

Solution code:
c = input().split()

s =  []
for i in c:
    if i == "*":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x*y)
    elif i == "-":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x-y)
    elif i == "+":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x+y)
    else:
        s.append(int(i))

print(s.pop(-1))

Submission status: Accepted

Solution code:
class stack:
    def __init__(self):
        self.s=[0 for _ in range(250)]
        self.top=0


    def push(self,x):
        self.s[self.top]=int(x)
        if(self.top< len(self.s)):
            self.top=self.top+1
        else:
            print('over flow')

    def pop(self):
        val=self.s[self.top-1]
        if (self.top > 0):
            self.top=self.top-1
        else:
            print('under flow')
        return val

inputs=input().split()
#print(inputs)
s=stack()
for _ in inputs:
    if _ !='+' and _ != '-' and _ !='*':
        s.push(_)
        #print(s.s)
    elif _ =='+':
        x=s.pop()+s.pop()
        s.push(x)
        #print(s.s)
    elif _ == '-':
        x=-s.pop()+s.pop()
        s.push(x)
        #print(s.s)
    elif _=='*':
        x=s.pop()*s.pop()
        s.push(x)
        #print(s.s)

print(s.pop())

Submission status: Accepted

Solution code:
l = list(input().split())
s = []
for p in l:
    if p == '+':
        s.append(s.pop() + s.pop())
    elif p == '-':
        s.append(-(s.pop() - s.pop()))
    elif p == '*':
        s.append(s.pop() * s.pop())
    else:
        s.append(int(p))

print(s.pop())

Submission status: Accepted

Solution code:
A = input().split()
n = len(A)
B = []

for i in range(n):
    B.append(A[i])
    if B[-1] == '+':
        B[-3] = int(B[-3]) + int(B[-2])
        B.pop()
        B.pop()
    elif B[-1] == '-':
        B[-3] = int(B[-3]) - int(B[-2])
        B.pop()
        B.pop()
    elif B[-1] == '*':
        B[-3] = int(B[-3]) * int(B[-2])
        B.pop()
        B.pop()

print(B[0])

Submission status: Accepted

Solution code:
def test():

	formula = input().split()
	stack = []

	for element in formula:

		if element == '+':

			a = stack.pop()
			b = stack.pop()
			stack.append(b+a)

		elif element == '-':

			a = stack.pop()
			b = stack.pop()
			stack.append(b-a)
			

		elif element == '*':

			a = stack.pop()
			b = stack.pop()
			stack.append(b*a)

		else:
			stack.append(int(element))


	print(stack.pop())

if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
A = map(str,input().split())
s = []

for a in A:
    if a in ['+', '-', '*']:
        b = s.pop()
        c = s.pop()
        
        if a == '+':
            s.append(b+c)
        elif a == '-':
            s.append(c-b)
        else:
            s.append(b*c)
    else:
        s.append(int(a))

ans = s.pop()
print(ans)

Submission status: Accepted

Solution code:
# global
in_list = []
# my_stack = []
register = []


if __name__ == "__main__":
    in_list = input().split(" ")
    for i in range(len(in_list)):
        if in_list[i].isdecimal():
            in_list[i] = int(in_list[i])

    for i in range(len(in_list)):
        if type(in_list[i]) is int:
            register.append(in_list[i])
        elif in_list[i] == "+":
            temp = register.pop() + register.pop()
            register.append(temp)
        elif in_list[i] == "-":
            temp = -register.pop() + register.pop()
            register.append(temp)
        elif in_list[i] == "*":
            temp = register.pop() * register.pop()
            register.append(temp)


    answer = register.pop()

    print(answer)

Submission status: Accepted

Solution code:
stack=[]
for i in input().split():
	if i.isdecimal():
		stack.append(i)
	else:
		a=stack.pop()
		b=stack.pop()
		stack.append(str(eval(b+i+a)))
print(stack[0])

Submission status: Accepted

Solution code:
X = input().split()

stack = []
for x in X:
    if x == "+":
        b = stack.pop()
        a = stack.pop()
        stack.append(a + b)
    elif x == "-":
        b = stack.pop()
        a = stack.pop()
        stack.append(a - b)
    elif x == "*":
        b = stack.pop()
        a = stack.pop()
        stack.append(a * b)
    else:
        stack.append(int(x))
print(stack[0])

Submission status: Accepted

Solution code:
strings = []

for string in input().strip().split():
  if string.isdigit():
    strings.append(string)
  else:
    strings.append(str(eval(strings.pop(-2) + string + strings.pop())))

print(strings.pop())

Submission status: Accepted

Solution code:
A = input().split()

def Revpol(A):
    S = [] #スタック
    for i in range(len(A)):
        if A[i] != '+' and A[i] != '-' and A[i] != '*':
            S.append(int(A[i]))
        elif len(S)>=2:
            if A[i] == '+':
                tmp = S[len(S)-2] + S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
            elif A[i] == '-':
                tmp = S[len(S)-2] - S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
            elif A[i] == '*':
                tmp = S[len(S)-2] * S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
        else:
            print("error1")
            break
    if len(S) == 1:
        print(S[0])
    else:
        print("error2")

Revpol(A)

Submission status: Accepted

Solution code:
def getInput():
    a = input().split()
    return a

def convNum(s):
    if s.isdigit():
        return int(s)
    else:
        return s
def initArr(len_a):
    return 0, [0 for i in range(len_a+1)]

def initTop():
    return 0

def isEmpty(top):
    return top == 0
    
def isFull(top, len_a):
    return top >= len_a-1

def pop(top, a):
    if isEmpty(top):
        print("Err: Empty")
    val = a[top]
    top -= 1
    return top, val

def push(top, a, val):
    if isFull(top, len(a)):
        print("Err: Full")
    top += 1
    a[top] = val
    return top

a = getInput()
a = [convNum(i) for i in a]

top, s = initArr(len(a))
for i in range(len(a)):
    top = push(top, s, a[i])
    if type(a[i]) == str:
        top, val = pop(top, s)
        top, val_b = pop(top, s)
        top, val_a = pop(top, s)
        if val == "+":
            top = push(top, s, val_a + val_b)
        elif val == "-":
            top = push(top, s, val_a - val_b)
        elif val == "*":
            top = push(top, s, val_a * val_b)        
        else:
            print("Error: Invalid Operand")
print(s[1])

Submission status: Accepted

Solution code:
a=input().split()

ls=[]
ln=len(a)

for i in range(ln):
    if a[i]=="+":
        ls[-2]+=ls[-1]
        ls.pop()
    elif a[i]=="-":
        ls[-2]-=ls[-1]
        ls.pop()
    elif a[i]=="*":
        ls[-2]*=ls[-1]
        ls.pop()
    else:
        ai=int(a[i])
        ls.append(ai)
        
print(ls[-1])

Submission status: Accepted

Solution code:
stack = [0]
top = 0

def push(x):
    global top
    top += 1
    stack.insert(top, x)

def pop():
    global top
    top -= 1
    return stack[top+1]

def main():
    input_line = input().split(" ")
    for i in input_line:
        if i == "+":
            a = pop()
            b = pop()
            push(a+b)
        elif i == "-":
            b = pop()
            a = pop()
            push(a-b)
        elif i == "*":
            a = pop()
            b = pop()
            push(a*b)
        else:
            push(int(i))
    
    print(pop())

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Stack():
  def __init__(self, max=100):
    self.max = max
    self.top = 0
    self.arr = [None for _ in range(max)]
  
  def is_empty(self):
    return self.top == 0

  def is_full(self):
    return self.top >= self.max - 1

  def push(self, x):
    if self.is_full():
      raise IndexError()
    self.top += 1
    self.arr[self.top] = x

  def pop(self):
    if self.is_empty():
      raise IndexError()
    self.top -= 1
    return self.arr[self.top + 1]

s = input().split()

stack = Stack(300)

for x in s:
  if x == "+":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b + a)
  elif x == "-":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b - a)
  elif x == "*":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b * a)
  else:
    stack.push(int(x))

print(stack.pop())

Submission status: Accepted

Solution code:
A = input().split(' ')
S = []
operator = ''
operand_1 = ''
operand_2 = ''

def operate(operator, operand_1, operand_2):
    if operator == '+':
        return operand_1 + operand_2
    
    elif operator == '-':
        return operand_1 - operand_2
    
    elif operator == '*':
        return operand_1 * operand_2

for i in range(len(A)):
    v = A[i]
    if v == '+' or v == '-' or v == '*':
        S.append(v)
        operator = S.pop()
        operand_2 = int(S.pop())
        operand_1 = int(S.pop())
        S.append(operate(operator, operand_1, operand_2))
        
    else:
        S.append(v)

print(str(S[0]))

Submission status: Accepted

Solution code:
s=list(input().split())
l=[]
for x in s:
    if x in ['+','-','*']:
        a,b=str(l.pop()),str(l.pop())
        b+=x + a
        l+=[int(eval(b))]
    else:l+=[int(x)]
print(l.pop())

Submission status: Accepted

Solution code:
class MyStack:
    def __init__(self):
        self._lst = []

    def push(self, val):
        self._lst.append(val)

    def pop(self):
        return self._lst.pop()

line_list = input().split()

stk = MyStack()

for t in line_list:
    if t == "+":
        stk.push(stk.pop() + stk.pop())
    elif t == "-":
        temp = stk.pop()
        stk.push(stk.pop() - temp)
    elif t == "*":
        stk.push(stk.pop() * stk.pop())
    else:
        stk.push(int(t))

print(stk.pop())

Submission status: Accepted

Solution code:
st = []

for c in input().split():
    if c in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else:
        st.append(c)
        
print(st[0])

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
line = list(map(str,input().split()))
 
#数字スタック
S = []
 
for tmp_ch in line:
 
    if tmp_ch in ['+','-','*']:
        b = int(S.pop())
        a = int(S.pop())
 
        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)
 
print("%d"%(S[0]))

Submission status: Accepted

Solution code:
expression = input().split()
stack = []
for i in expression:
    if i in ['+', '-', '*']:
        a = stack.pop()
        b = stack.pop()
    if i == '+':
        stack.append(b + a)
    elif i == '-':
        stack.append(b - a)
    elif i == '*':
        stack.append(b * a)
    else:
        stack.append(int(i))

print(stack[0])

Submission status: Accepted

Solution code:
mathlist=list(map(str,input().split()))
resultlist = []
for ope in mathlist:
    if ope == "+":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number1 + number2
        resultlist.append(result)
    elif ope =="*":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number1 * number2
        resultlist.append(result)
    elif ope =="-":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number2 - number1
        resultlist.append(result)
    else:
        result = ope
        resultlist.append(result)
print(*resultlist)

Submission status: Accepted

Solution code:
A=list(input().split())
Max=101
numstack=[0]*Max
top=0
def pop():
  if isEmpty():
    print('error')
  global top
  global numstack
  top-=1
  return numstack[top+1]

def push(x):
  if isFull():
    print('error')
  global top
  top+=1
  global numstack
  numstack[top]=x

def isEmpty():
  return top==0

def isFull():
  return top==Max-1

for i in range(len(A)):
  if A[i]=='+':
    push(pop()+pop())
  elif A[i]=='-':
    push(-pop()+pop())
  elif A[i]=='*':
    push(pop()*pop())
  else:
    push(int(A[i]))
print(numstack[1])

Submission status: Accepted

Solution code:
s = input().split()
a = []

for x in s:
    if x not in "+-*":
        a += [int(x)]
    else:
        c = str(a.pop())
        b = str(a.pop())
        b += x + c
        a += [int(eval(b))]

print(a.pop())

Submission status: Accepted

Solution code:
input_list = input().split()
stack = []

for item in input_list:
  try:
    num = int(item)
    stack.append(num)

  except ValueError:
    num2 = stack.pop()
    num1 = stack.pop()

    if item == '+':
      stack.append(num1 + num2)
    elif item == '-':
      stack.append(num1 - num2)
    elif item == '*':
      stack.append(num1 * num2)
    elif item == '/':
      stack.append(num1 / num2)

print(stack.pop())

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self, n):
        self.S = [0 for i in range(n)]
        self.top = 0
        self.Max = n + 1

    def isEmpty(self):
        return self.top == 0

    def isFull(self):
        return self.top >= self.Max - 1

    def push(self, x):
        tf = self.isFull()
        if not tf:
            self.top += 1
            self.S[self.top] = x

    def pop(self):
        tf = self.isEmpty()
        if not tf:
            self.top -= 1
            return self.S[self.top + 1]


l = list(input().split())
n = len(l)
st = Stack(n)

for i in l:
    if i != "+" and i != "-" and i != "*":
        st.push(int(i))
    else:
        b = st.pop()
        a = st.pop()
        if i == "+":
            st.push(a+b)
        elif i == "-":
            st.push(a-b)
        elif i == "*":
            st.push(a*b)

print(st.S[1])

Submission status: Accepted

Solution code:
def porland(M):
    for i in range(len(M)):
        if len(M)==1:
            print(' '.join(map(str, M)))
        elif M[i]=='+':
            M[i] = int(M[i-2])+int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        elif M[i]=='-':
            M[i] = int(M[i-2])-int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        elif M[i]=='*':
            M[i] = int(M[i-2])*int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        else :
            M[i] = int(M[i])

if __name__ == '__main__':
    N = list(input().split())
    porland(N)

Submission status: Accepted

Solution code:
from typing import List


def stack_push(elems: List[int], value: int) -> None:
    elems.append(value)


def stack_pop(elems: List[int]) -> int:
    value = elems.pop()
    return value


def exec_operation(elems: List[int], operation: str) -> None:
    value2 = elems.pop()
    value1 = elems.pop()
    if ("+" == operation):
        elems.append(value1 + value2)
    elif ("-" == operation):
        elems.append(value1 - value2)
    elif ("*" == operation):
        elems.append(value1 * value2)


if __name__ == "__main__":
    stack: List[int] = []
    input_commands = input().split(" ")

    for command in input_commands:
        if (str.isdecimal(command)):
            stack_push(stack, int(command))
        else:
            exec_operation(stack, command)

    print(f"{stack_pop(stack)}")

Submission status: Accepted

Solution code:
class Stack:
    #li = []
    def __init__(self):
        self.li = []
        self.top = 0
    def push(self,value):
        #self.li.insert(0,argv)
        self.li.append(int(value))
        self.top += 1
    def pop(self):
        self.top -= 1
        return self.li.pop()
    def isEmpty(self):
        return len(li)==0
    def __str__(self):
        return str(self.li[0])

l = list(map(str,input().split()))

save = Stack()

symble = ["+","-","*"]

for i in l:
    #print(save)
    if i in symble:
        b = save.pop()
        a = save.pop()
        if i=="+":
            save.push(a + b)
        elif i=="-":
            save.push(a - b)
        else:
            save.push(a * b)
    else:
        save.push(i)
else:
    print(save)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    data = input().split()
    stack = []

    for i in data:
        if i == '+':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv + rhv)
        elif i == '-':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv - rhv)
        elif i == '*':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv * rhv)
        else:
            stack.append(int(i))
    
    print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, data=[]):
        self.data = data

    def push(self, x):
        self.data.append(x)
        return self.data

    def pop(self):
        if len(self.data) == 0:
            return "Stack is Empty"
        else:
            return self.data.pop()


stack = Stack()
formula = list(map(str, input().split()))
for i in range(len(formula)):
    if formula[i] == '+':
        b = stack.pop()
        a = stack.pop()
        stack.push(a+b)
    elif formula[i] == '-':
        b = stack.pop()
        a = stack.pop()
        stack.push(a-b)
    elif formula[i] == '*':
        b = stack.pop()
        a = stack.pop()
        stack.push(a*b)
    else:
        stack.push(int(formula[i]))

print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque


def main():
    sequence = [e for e in input().split(' ')]
    stack = deque()
    for e in sequence:
        if '+' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(a + b)
        elif '-' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(b - a)
        elif '*' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(a * b)
        else:
            stack.append(int(e))
    print(stack.pop())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
from sys import stdin
L = stdin.readline().rstrip().split()
d = deque()
for s in L:
    if s.isdigit():
        d.append(int(s))
    else:
        a = d.pop()
        b = d.pop()
        if s == '+':
            d.append(b+a)
        elif s == '-':
            d.append(b-a)
        elif s == '*':
            d.append(b*a)
print(d[0])

Submission status: Accepted

Solution code:
eq=list(map(str,input().split()))
n=len(eq)
ans=[]
for a in range(0,n):
    if eq[a]!="+" and eq[a]!="-" and eq[a]!="*":
        ans.append(int(eq[a]))
    elif eq[a]=="+":
        ans[-2]+=ans[-1]
        ans.pop()
    elif eq[a]=="-":
        ans[-2]=ans[-2]-ans[-1]
        ans.pop()
    elif eq[a]=="*":
        ans[-2]*=ans[-1]
        ans.pop()
print(ans[0])

Submission status: Accepted

Solution code:
operand=list(map(str,input().split()))
stack=[]
for i in range(len(operand)):
    if operand[i]=="+":
        a=stack.pop()
        b=stack.pop()
        stack.append(a+b)
    elif operand[i]=="-":
        a=stack.pop()
        b=stack.pop()
        stack.append(b-a)
    elif operand[i]=="*":
        a=stack.pop()
        b=stack.pop()
        stack.append(a*b)
    else:
        stack.append(int(operand[i]))
print(stack[0])

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, n):
        self.top = 0
        self.A = [0 for i in range(n)]
        self.n = n

    def init(self):
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top == self.n - 1

    def push(self, x):
        if not self.is_full():
            self.top += 1
            self.A[self.top] = x

    def pop(self):
        if not self.is_empty():
            x = self.A[self.top]
            self.top -= 1
            return x


if __name__ == '__main__':
    S = Stack(110)
    for ch in raw_input().split():
        if ch == '+':
            b = S.pop()
            a = S.pop()
            S.push(a + b)
        elif ch == '-':
            b = S.pop()
            a = S.pop()
            S.push(a - b)
        elif ch == '*':
            b = S.pop()
            a = S.pop()
            S.push(a * b)
        else:
            S.push(int(ch))
    print S.pop()