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:
def calc(a):
    b = []
    for i in a:
        v = 0
        if i.isnumeric():
            b.append(int(i))
        else:
            if i == '+':
                for _ in range(2):
                    v += b.pop()
                b.append(v)
            elif i == '-':
                for _ in range(2):
                    if _ == 0:
                        v -= b.pop()
                    else:
                        v += b.pop()
                b.append(v)
            elif i == '*':
                for _ in range(2):
                    if _ == 0:
                        v += b.pop()
                    else:
                        v *= b.pop()
                b.append(v)
    return b


if __name__ == '__main__':
    l = input().split()
    print(calc(l)[0])

Submission status: Accepted

Solution code:
def main():
    r_p_formula = list(input().split())
    
    stack = []
    res = 0
    for element in r_p_formula:
        try:
            num = int(element)
            stack.append(num)
            
        except ValueError:
            last_num = stack.pop()
            sec_last_num = stack.pop()
            stack.append(calc(sec_last_num, last_num, element))
            
    print(stack.pop())

def calc(num1, num2, ope):
    if ope == "+":
        return num1 + num2
    elif ope == "-":
        return num1 - num2
    elif ope == "*":
        return num1 * num2
    else:
        return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num_list=list(map(str,input().split()))

stack=[]


for i in range(0,len(num_list)):
    if num_list[i]=="+":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2+tmp1
        stack.append(ans) 
    elif num_list[i]=="*":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2*tmp1
        stack.append(ans) 
    elif num_list[i]=="-":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2-tmp1
        stack.append(ans) 
    elif num_list[i]=="/":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2/tmp1
        stack.append(ans) 
    else:
        stack.append(num_list[i])
print(stack[0])

Submission status: Accepted

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

for s in lst:
    if s == "+":
        stack += [stack.pop() + stack.pop()]
    elif s == "-":
        stack += [-stack.pop() + stack.pop()]
    elif s == "*":
        stack += [stack.pop() * stack.pop()]
    else:
        stack += [int(s)]

print(stack.pop())

Submission status: Accepted

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

for i in F:
    try:
        stack.append(int(i))
    except ValueError:
        exec(
            f"temp = stack[-2] {i} stack[-1];"
            "stack.pop();"
            "stack.pop();"
            "stack.append(temp);"
            )

print(stack[0])

Submission status: Accepted

Solution code:
input_list = input().rstrip().split(" ")

stack = []
for i in input_list:
    if i in ["+", "-", "*"]:
        num_1 = stack.pop()
        num_2 = stack.pop()
        stack.append(str(eval(num_2 + i + num_1)))
    else:
        stack.append(i)
answer = stack.pop()
print(answer)

Submission status: Accepted

Solution code:
from collections import deque

s = input().split()
l = deque()

for i in s:
    if i in ['+', '-', '*', '/']:
        a = l.pop()
        b = l.pop()
        l.append(str(eval(b+i+a)))
    else:
        l.append(i)
print(l[0])

Submission status: Accepted

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

for i in s:
    if i == '+':
        a = l.pop()
        b = l.pop()
        l.append(a+b)
    elif i == '-':
        b = l.pop()
        a = l.pop()
        l.append(a-b)
    elif i == '*':
        a = l.pop()
        b = l.pop()
        l.append(a*b)
    else:
        l.append(int(i))

for j in l:
    print(j)

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def main():
    S = input().split()

    stack = deque()
    for s in S:
        if s in ["+", "-", "*"]:
            b = stack.pop()
            a = stack.pop()
            c = str(eval(a + s + b))
            stack.append(c)
        else:
            stack.append(s)
    ans = stack.pop()
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
stack = [0]*1000
top = 0

def push(x):
    global stack
    global top

    top += 1
    stack[top] = x

def pop():
    global top
    global stack

    top -= 1
    return(stack[ top + 1 ])

def main():
    global stack
    global top
    a = 0
    b = 0

    A = list(input().split())

    for i in range(len(A)):
        if A[i] not in ['+','-','*']:
            push(int(A[i]))
        elif A[i] == '+':
            a = pop()
            b = pop()
            push(b+a)
        elif A[i] == '-':
            a = pop()
            b = pop()
            push(b-a)
        elif A[i] == '*':
            a = pop()
            b = pop()
            push(b*a)

    return stack[1]

print(main())

Submission status: Accepted

Solution code:
def cal(x,y,o):
    x,y=int(x),int(y)
    if o=="+":
        return x+y
    if o=="-":
        return x-y
    if o=="*":
        return x*y
    if o=="/":
        return x/y

def RPN(shiki):#式のリスト
    stack=[]
    operator=["+","-","*","/"]
    for x in shiki:#数字をスタックに格納
        if x not in operator:
            stack.append(int(x))
        else:#演算子なら直前の２つの数字を演算してスタックに格納
            s=stack.pop()
            f=stack.pop()
            stack.append(cal(f,s,x))
    return stack[-1]

shiki=list(input().split())
print(RPN(shiki))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

S = raw_input().split()

lst = []

for s in S:
    if s == '+':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num1 + num2)
    
    elif s == '-':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num2 - num1)
        
    elif s == '*':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num2 * num1)
        
    else:
        lst.append(int(s))

print lst[0]

Submission status: Accepted

Solution code:
S=input().split()
operand=[]
cnt=0

# 1 2 + 3 4 - *
# -> (1 + 2) * (3 - 4)
for s in S:
  if s in '+-*':
    a=operand.pop()
    b=operand.pop()
    x=eval(b+s+a)
    #tmp=operand.pop()+s+operand.pop()
    #print(tmp)
    #x=eval(tmp)
    operand.append(str(x))
  else:
    operand.append(s)

print(operand.pop())

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self):
        self.top = 1
        self.array = [None]*1000

    def push(self, x):
        if not self.isFull():
            self.array[self.top] = x
            self.top += 1
        else:
            raise ValueError()

    def pop(self):
        if not self.isEmpty():
            self.top -= 1
            val = self.array[self.top]
            return val
        else:
            raise ValueError()

    def isEmpty(self):
        if self.top == 1:
            return True
        else:
            return False

    def isFull(self):
        if self.top >= 999:
            return True
        else:
            return False


def main():
    S = input().split()
    stack = Stack()
    operands = ["+", "-", "*"]
    for s in S:
        if s not in operands:
            stack.push(int(s))

        else:
            val1 = stack.pop()
            val2 = stack.pop()
            if s == "+":
                val = val1 + val2
                stack.push(val)
            elif s == "-":
                val = val2 - val1
                stack.push(val)
            else:
                val = val1 * val2
                stack.push(val)
    ans = stack.pop()
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

inp = stdin.readline().rstrip().split()
stack = []

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

Submission status: Accepted

Solution code:
A = list(map(str, input().split()))

l = []
for n in A:
    ans = 0
    if n.isnumeric():
        l.append(int(n))
    elif n == '+':
        ans = l[-2] + l[-1]
        l[-2] = ans
        l.pop()
    elif n == '-':
        ans = l[-2] - l[-1]
        l[-2] = ans
        l.pop()
    elif n == '*':
        ans = l[-2] * l[-1]
        l[-2] = ans
        l.pop()
        
print(l[0])

Submission status: Accepted

Solution code:
a = list(map(str, input().split()))


stack = []
i = 0
 
for i in range(len(a)):
    if a[i] == '+':
        stack.append(stack.pop() + stack.pop())
    elif a[i] == '-':
        stack.append(- stack.pop() + stack.pop())
    elif a[i] == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(a[i]))
else:
    print(stack[0])

Submission status: Accepted

Solution code:
def resolve():
    from collections import deque
    A = [i for i in input().split()]
    que = deque()
    for s in A:
        if s in "+-*":
            b = que.pop()
            a = que.pop()
            tmp = str(eval(a + s + b))
            que.append(tmp)
        else:
            que.append(s)
    print(que.popleft())


resolve()

Submission status: Accepted

Solution code:
value = []
for c in input().split():
    if c in "+-*":
        n2 = value.pop()
        n1 = value.pop()
        value.append(str(eval(n1 + c + n2)))
    else:
        value.append(c)
print(value[0])

Submission status: Accepted

Solution code:
a= list(input().split())
for i in range(len(a)):
    if a[i] !="+" and a[i] !="-"and a[i] !="*":
        a[i]=int(a[i])
i= 0
while len(a)>1:
    if a[i] =="+":
        temp= a[i-2]+ a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    elif a[i] =="-":
        temp= a[i-2]- a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    elif a[i] =="*":
        temp= a[i-2]* a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    else:
        i= i+ 1
print(a[0])

Submission status: Accepted

Solution code:
list = input().split()
stack = []
for i in list:
    if i == '+':
        x = stack.pop()
        y = stack.pop()
        stack.append(y+x)
    elif i == '-':
        x = stack.pop()
        y = stack.pop()
        stack.append(y-x)
    elif i == '*':
        x = stack.pop()
        y = stack.pop()
        stack.append(y*x)
    else:
        stack.append(int(i))
print(stack[0])

Submission status: Accepted

Solution code:
a = str(input()).split(' ')
calc = []
for i in range(len(a)):
    if a[i] == '+':
        p = calc.pop()
        q = calc.pop()
        calc.append(p + q)
    elif a[i] == '-':
        p = calc.pop()
        q = calc.pop()
        calc.append(q - p)
    elif a[i] == '*':
        p = calc.pop()
        q = calc.pop()
        calc.append(p * q)
    else:
        calc.append(int(a[i]))
print(calc[0])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input().split()
    stack = []
    for st in S:
        if st == '+':
            b = stack.pop()
            a = stack.pop()
            stack.append(a + b)
        elif st == '-':
            b = stack.pop()
            a = stack.pop()
            stack.append(a - b)
        elif st == '*':
            b = stack.pop()
            a = stack.pop()
            stack.append(a*b)
        else:
            stack.append(int(st))
    ans = stack[0]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    f = input().split()
    stack = list()
    for i in f:
        if i.isdigit():
            stack.append(i)
        else:
            se = stack.pop()
            fi = stack.pop()
            tmp = eval(fi+i+se)
            stack.append(str(tmp))
    print(stack.pop())
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ls = list(input().split())


class Stack:
    def __init__(self):
        self.stack = []

    def push(self, item):
        self.stack.append(item)

    def pop(self):
        if len(self.stack) == 0:
            return None
        return self.stack.pop()


stack = Stack()
for s in ls:
    if s in ['+', '-', '*']:
        v2 = stack.pop()
        v1 = stack.pop()
        stack.push(str(eval(v1+s+v2)))
    else:
        stack.push(s)
print(stack.stack[0])

Submission status: Accepted

Solution code:
args = input().split(' ')
stack = []
for arg in args:
    if arg.isdecimal():
        stack.append(int(arg))
    elif arg == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(a + b)
    elif arg == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif arg == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(a * b)
print(stack.pop())

Submission status: Accepted

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

for x in s:
    if x.isdigit():
        stack.append(x)
    else:
        right = stack.pop()
        left = stack.pop()
        res = eval(left + x + right)
        stack.append(str(res))
print(int(stack.pop()))

Submission status: Accepted

Solution code:
from collections import deque

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

S=deque([])

for i in range(len(D)):
    if str.isnumeric(D[i])==True:
        S.append(int(D[i]))
    else:
        A=S.pop()
        B=S.pop()
        if D[i]=="+":
            S.append(A+B)
        elif D[i]=="-":
            S.append(B-A)
        else:
            S.append(A*B)
    
print(S[0])

Submission status: Accepted

Solution code:


from collections import deque


top=0
S=deque()
array=input().split(" ")

for i in range(len(array)):
  s=array[i]
  if s=="+":
    a=S.pop()
    b=S.pop()
    S.append(a+b)
  elif s=="-":
    a=S.pop()
    b=S.pop()
    S.append(b-a)
  elif s=="*":
    a=S.pop()
    b=S.pop()
    S.append(a*b)
  else:
    S.append(int(s))
print(S.pop())

Submission status: Accepted

Solution code:
por_list = list(input().split(' '))

stack = []


for i in por_list:
    try:
        stack.append(int(i))
    except ValueError:
        x = stack.pop()
        y = stack.pop()
        if i == '+':
            stack.append(x+y)
        elif i == '-':
            stack.append(y-x)
        elif i == '*':
            stack.append(x*y)
print(stack.pop())

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    A = input().split()
    stack = []
    for s in A:
        stack.append(s)
        if s == "+":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a + b)
        elif s == "-":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(b - a)
        elif s == "*":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a * b)

    print(stack[0])

Submission status: Accepted

Solution code:
A = input().split()
S = []
for a in A:
    if a in ['+', '-', '*']:
        s = eval(S[-2] + a + S[-1])
        S = S[:-2]
        S.append(str(s))
    else:
        S.append(a)
print(*S)

Submission status: Accepted

Solution code:
class stack:

    data = []

    def push(self, a):
        self.data.append(a)

    def pop(self):
        if len(self.data) > 0:
            top = self.data[-1]
            self.data = self.data[:-1]
            return top
        else:
            raise Exception('stack has no data.')

buf = stack()
op = ['+', '*', '-']

a = list(input().split())
for i in a:
    if i in op:
        op2 = int(buf.pop())
        op1 = int(buf.pop())
        if i == '+':
            buf.push(op1+op2)
        elif i == '*':
            buf.push(op1*op2)
        else:
            buf.push(op1-op2)
    else:
        buf.push(i)
result = buf.pop()
print(result)

Submission status: Accepted

Solution code:
num_str_list = list(input().split())
answer_list = []

for i in num_str_list:
    if i in "+-*":
        v1 = answer_list.pop()
        v2 = answer_list.pop()
        if i == "+":
            v3 = int(v2) + int(v1)
            answer_list.append(v3)
        if i == "-":
            v3 = int(v2) - int(v1)
            answer_list.append(v3)
        if i == "*":
            v3 = int(v2) * int(v1)
            answer_list.append(v3)
    else:
        answer_list.append(i)
        
print(answer_list[0])

Submission status: Accepted

Solution code:
a=list(input().split())
def reverse_porand(r):
    s=[]#stack配列の用意
    for i in range(len(r)):#stackは左から読むのが当たり前なので、for文でよい
        if r[i]=="+":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(a+b)
        elif r[i]=="-":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(b-a)
        elif r[i]=="*":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(a*b)
        else:
            s.append(int(r[i]))#数字なら流す
    print(s[-1])

reverse_porand(a)

Submission status: Accepted

Solution code:
# ALDS1_3_A.py
from collections import deque as stack
S = input().split()
q = stack([])
# print(S)
for i in S:
    # print("i:", i)
    if i == "+":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a+b)
        # print("+:", a, b)
    elif i == "-":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a-b)
        # print("-:", a, b)
    elif i == "*":
        b = int(q.pop())
        a = int(q.pop())
        # print("*:", a, b)
        q.append(a*b)
    else:
        q.append(int(i))
print(q.pop())

Submission status: Accepted

Solution code:
n = input()
v = [n.lower() for n in n.split()]

stack = []
idx = 0
loop_cnt = 0

for num in v:
    try:
        if int(num):
            stack.append(num)
    except:
        if num == "+":
            calc = int(stack[idx - 2]) + int(stack[idx - 1])
        elif num == "-":
            calc = int(stack[idx - 2]) - int(stack[idx - 1])
        elif num == "*":
            calc = int(stack[idx - 2]) * int(stack[idx - 1])

        for i in range(0,2):
            stack.pop(idx - 1)
        stack.append(calc)
        idx = 0
        loop_cnt = 0

print(stack[0])

Submission status: Accepted

Solution code:
from typing import List, Union


class Stack():
    def __init__(self):
        self.top = 0
        self.max = 200
        self.lst = [None] * self.max

    def is_empty(self) -> bool:
        if self.top == 0:
            return True
        else:
            return False

    def is_full(self) -> bool:
        if self.top >= self.max - 1:
            return True
        else:
            return False

    def push(self, x: int) -> bool:
        if self.is_full() == True:
            print("ERROR: OVERFLOW")
            return False
        self.top += 1
        self.lst[self.top] = x
        return True

    def pop(self) -> Union[bool, int]:
        if self.is_empty() == True:
            print("ERROR: UNDERFLOW")
            return False
        self.top -= 1
        return self.lst[self.top + 1]


def main():
    lst: List = list(input().split())
    S = Stack()

    for char in lst:
        if char == "+":
            b = S.pop()
            a = S.pop()
            S.push(a + b)
        elif char == "-":
            b = S.pop()
            a = S.pop()
            S.push(a - b)
        elif char == "*":
            b = S.pop()
            a = S.pop()
            S.push(a * b)
        else:
            S.push(int(char))

    print(S.lst[S.top])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in input:
    if i.isdigit():
        stack.append(i)
    else:
        s = stack.pop()
        f = stack.pop()
        stack.append(str(eval(f+i+s)))

print(int(stack.pop()))

Submission status: Accepted

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

for item in formula:
    if item == '+' or item == '-' or item == '*':
        a = stack.pop()
        b = stack.pop()
        if item == '+':
            c = a + b
        elif item == '-':
            c = b - a
        else:
            c = a * b
        stack.append(c)
    else:
        stack.append(int(item))
print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque

def calc(b,a,s):
    if s == '+':
        return a + b
    if s == '-':
        return a - b
    if s == '*':
        return a * b

L = input().split()
S = deque()
for c in L:
    if c in ['+','-','*']:
        S.append(calc(int(S.pop()), int(S.pop()), c))
    else:
        S.append(c)
print(S[0])

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = LSS()
    stk = []
    for i in S:
        if i in ['+', '-', '*']:
            a = stk.pop()
            b = stk.pop()
            if i=='+':
                stk.append(b+a)
            elif i=='-':
                stk.append(b-a)
            elif i=='*':
                stk.append(b*a)
        else:
            stk.append(int(i))

    print(stk[0])

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
stack = []

for v in input().split():
    if v == '+':
        n2 = stack.pop()
        n1 = stack.pop()
        stack.append(n1 + n2)
    elif v == '-':
        n2 = stack.pop()
        n1 = stack.pop()
        stack.append(n1 - n2)
    elif v == '*':
        n2 = stack.pop()
        n1 = stack.pop()
        stack.append(n1 * n2)
    else:
        stack.append(int(v))

ans = stack.pop()
print(ans)

Submission status: Accepted

Solution code:
def cal(n1, n2, o):
    if o == "+":
        return str(n1 + n2)
    elif o == "-":
        return str(n1 - n2)
    elif o == "*":
        return str(n1 * n2)

S = input().split()
i = 0
while len(S) > i:
    if S[i] == "+" or S[i] == "-" or S[i] == "*":
        r = cal(int(S[i-2]), int(S[i-1]), S[i])
        del S[i-2:i+1]
        S.insert(i-2, r)
        i = 0
    else:
        i += 1

print(S[0])

Submission status: Accepted

Solution code:
class Stack:
    """Stack"""
    def __init__(self):
        self.Clear()

    def Clear(self):
        self.Stack = []

    def push(self, dat):
        self.Stack.append(dat)
        return self.Stack

    def pop(self):
        if len(self.Stack) == 0:
            return None
        return self.Stack.pop()

s = [i for i in input().split()]
stack = Stack()
for i in range(len(s)):
    if s[i] == '+':
        s_1 = stack.pop()
        s_2 = stack.pop()
        stack.push(s_1 + s_2)
    elif s[i] == '-':
        s_3 = stack.pop()
        s_4 = stack.pop()
        stack.push(s_4 - s_3)
    elif s[i] == '*':
        s_5 = stack.pop()
        s_6 = stack.pop()
        stack.push(s_5 * s_6)
    else:
        stack.push(int(s[i]))
    
        
print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque
D = deque([])
for i in map(str,input().split()):
    if i.isdecimal():
        D.append(i)
    else:
        i1 = D.pop()
        i2 = D.pop()
        D.append(str(eval(i2+i+i1)))
else:
    print(D.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = []

for c in input().split():
    if c in "+-*":
        b = S.pop()
        a = S.pop()
        s = str(eval(a+c+b))
        S.append(s)
    else:
        S.append(c)
print(S[0])

Submission status: Accepted

Solution code:
f = input().strip().split()
q = []
for e in f:
    if e == '+':
        q.append(q.pop() + q.pop())
    elif e == '-':
        q.append(-q.pop() + q.pop())
    elif e == '*':
        q.append(q.pop() * q.pop())
    else:
        q.append(int(e))
print(q[0])

Submission status: Accepted

Solution code:
import sys
import os


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

for c in lst:
    if c == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(b + a)
    elif c == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif c == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(b * a)
    else:
        stack.append(int(c))
print(stack[0])

Submission status: Accepted

Solution code:
from collections import deque
d = deque()
a = list(map(str, input().split()))
for i in a:
    if i == "+":
        a1 = d.pop()
        a2 = d.pop()
        d.append(a1+a2)
    elif i == "-":
        a1 = d.pop()
        a2 = d.pop()
        d.append(a2-a1)
    elif i == "*":
        a1 = d.pop()
        a2 = d.pop()
        d.append(a1*a2)
    else:
        d.append(int(i))
print(d.pop())

Submission status: Accepted

Solution code:
statement = input().split()
stack = []
for s in statement:
    if s in "+-*":
        x = stack.pop()
        y = stack.pop()
        sum = str(eval(y + s + x))
        stack.append(sum)
    else:
        stack.append(s)
print(stack[0])

Submission status: Accepted

Solution code:
def Stack(order_list):
    cal_list = []
    for content in order_list:
        if content == "+":
            b = cal_list.pop()
            a = cal_list.pop()
            cal_list.append(a+b)
        elif content == "-":
            b = cal_list.pop()
            a = cal_list.pop()
            cal_list.append(a-b)
        elif content == "*":
            b = cal_list.pop()
            a = cal_list.pop()
            cal_list.append(a*b)
        else:
            cal_list.append(int(content))
            
    return cal_list[0]
    
order_list = input().split()
ans = Stack(order_list)
print(ans)

Submission status: Accepted

Solution code:
class stack():
    def __init__(self):
        self.S = [0 for i in range(200)]
        self.top = 0
        self.MAX =200
    def isEmpty(self):
        return self.top == 0
    def isFull(self):
        return self.top >= self.MAX -1
    def push(self,x):
        if self.isFull():
            print('error')
        self.top += 1
        self.S[self.top] = x
    def pop(self):
        if self.isEmpty():
            print('error')
            
        self.top -= 1
        return self.S[self.top+1]
l = input().split()
s = stack()
for i in l:
    if i == '+':
        a = s.pop()
        b = s.pop()
        s.push(a+b)
    elif i == '-':
        a = s.pop()
        b = s.pop()
        s.push(b-a)
    elif i =='*':
        a = s.pop()
        b = s.pop()
        s.push(a*b)
    else:
        s.push(int(i))
print(s.S[1])

Submission status: Accepted

Solution code:
class stack:
    val = []
    def __init__(self,arg):
        self.val = arg

    def stack_push(self,a):
        self.val.append(a)

    def stack_pop(self):
        return self.val.pop()

N = input().split()
Output = stack([])

for a in N:
    if a.isdigit():
        Output.stack_push(a)
    else:
        temp1 = int(Output.stack_pop())
        temp2 = int(Output.stack_pop())
        if a == '+':
            Output.stack_push(temp2+temp1)
        elif a == '-':
            Output.stack_push(temp2-temp1)
        elif a == '*':
            Output.stack_push(temp2*temp1)
        elif a == '/':
            Output.stack_push(temp2/temp1)
print(Output.stack_pop())

Submission status: Accepted

Solution code:
import math
import sys
import itertools

def main():
  f = input().split()

  while len(f) > 1:

    len_f = len(f)

    for i in range(len_f):
      if f[i] == '+' or f[i] == '-' or f[i] == '*':
        index = i
        operator = f[i]
        break

    if operator == '+':
      r = int(f[index-2]) + int(f[i-1])
    elif operator == '-':
      r = int(f[index-2]) - int(f[index-1])
    elif operator == '*':
      r = int(f[index-2]) * int(f[index-1])
    else:
      print('invalid input')
      sys.exit(1)

    f = f[:index-2] + [str(r)] + f[index+1:]

  print(f[0])

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
ope = list(input().split())
stack = list()

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

print(stack[0])

Submission status: Accepted

Solution code:
class stackClass:

	def __init__(self):
		self.array = []

	def push(self, x):
		self.array.append(x)

	def pop(self):
		a = self.array[len(self.array)-1]
		del self.array[len(self.array)-1]
		return a

	def isFull(self):
		return False

	def isEmpty(self):
		if len(self.array) == 0:
			return True
		else:
			return False


ilst = input().split()
stack = stackClass()
for i in ilst:
	if i == '+':
		a = stack.pop()
		b = stack.pop()
		stack.push(b + a)
	elif i == '-':
		a = stack.pop()
		b = stack.pop()
		stack.push(b - a)
	elif i == '*':
		a = stack.pop()
		b = stack.pop()
		stack.push(b * a)
	else:
		stack.push(int(i))

print(stack.pop())