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 = list(input().split())
stack = []

while len(symbol) > 0:
    x = symbol.pop(0)
    if x.isdigit():
        stack.append(int(x))
    else:
        a,b = stack.pop(),stack.pop()
        if x == "+":
            stack.append(b + a)
        elif x == "-":
            stack.append(b - a)
        elif x == "*":
            stack.append(b * a)

print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque as D
line, stack = D(input().split()), D()
while line:
    hoge = line.popleft()
    if hoge.isdigit():
        stack.append(hoge)
    else:
        a, b = int(stack.pop()),int(stack.pop())
        if hoge =="*":
            stack.append(a*b)
        elif hoge == "+":
            stack.append(a+b)
        elif hoge == "-":
            stack.append(b-a)
        else:
            stack.append(b//a)
print(stack.popleft())

Submission status: Accepted

Solution code:
def add(x,y):
    return x+y
def sub(x,y):
    return x-y
def mul(x,y):
    return x*y
def div(x,y):
    return x/float(y)

a=input().split()
i=0
for j in range(len(a)):
    if a[i]=="+":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(add(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="-":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(sub(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="*":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(mul(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="/":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(div(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    i=i+1
print(a[0])

Submission status: Accepted

Solution code:

list=input().split()

i=0

for j in range(len(list)):
	if list[i]=='+':
		list[i]=int(list[i-1])+int(list[i-2])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='-':
		list[i]=int(list[i-2])-int(list[i-1])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='*':
		list[i]=int(list[i-1])*int(list[i-2])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='/':
		list[i]=int(list[i-2])/float(list[i-1])
		del list[i-2]
		del list[i-2]
		i-=2
	i+=1

print(list[0])

Submission status: Accepted

Solution code:
a=input().split()
b=[]
for i in range(len(a)):

	if a[i]=="+":

		b[len(b)-2]=b[len(b)-2]+b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="-":

		b[len(b)-2]=b[len(b)-2]-b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="*":

		b[len(b)-2]=b[len(b)-2]*b[len(b)-1];
		del b[len(b)-1]

	else:
		b.append(int(a[i]))

		
print(b[len(b)-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=input().split()
l=len(A)
x=[]

for i in range(l):
    
    if A[i]=="+":
        a=x.pop() #先頭の文字を消して返す
        b=x.pop()
        x.append(int(b)+int(a))

    elif A[i]=="-":
        a=x.pop()
        b=x.pop()
        x.append(int(b)-int(a))

    elif A[i]=="*":
        a=x.pop()
        b=x.pop()
        x.append(int(b)*int(a))

    else:
        x.append(A[i])

print(x[0])

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, full_idx=10):
        self.stack = [None] * full_idx
        self.top = 0
        self.MAX = full_idx

    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.stack[self.top] = x

    def pop(self):
        if self.is_empty():
            raise IndexError

        self.top -= 1
        return self.stack[self.top+1]


def main():
    e = input().split()
    s = Stack(101)

    for i in range(len(e)):
        if e[i].isdigit():
            s.push(int(e[i]))
        elif e[i] == '+':
            a, b = s.pop(), s.pop()
            s.push(a+b)
        elif e[i] == '-':
            a, b = s.pop(), s.pop()
            s.push(b-a)
        else:
            a, b = s.pop(), s.pop()
            s.push(a*b)

    print(s.pop())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def main():
    l = input().split(' ')

    while len(l) > 1:
        idx = 0
        while l[idx] not in ["+", "-", "*"]:
            idx += 1
        res = str(eval(str(l[idx-2] + l[idx] + l[idx-1])))
        l[idx-2] = res
        l.pop(idx-1)
        l.pop(idx-1)

    print(l[0])

main()

Submission status: Accepted

Solution code:

def main():
    l = input().split(' ')

    s = []

    for el in l:
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()

Submission status: Accepted

Solution code:
L = input().split()
n = len(L)
A  = []
top = -1
for i in range(n):
    if L[i] not in {"+","-","*"}:
        A.append(int(L[i]))
        top += 1
    else:
        if(L[i] == "+"):
            A[top - 1] = A[top - 1] + A[top]
        elif(L[i] == "-"):
            A[top - 1] = A[top -1] - A[top]
        elif(L[i] == "*"):
            A[top - 1] = A[top - 1] * A[top]
        del A[top]
        top -= 1
print(A[top])

Submission status: Accepted

Solution code:
input_list = list(map(str, input().split()))
stack_list = []

for i in input_list:
    if i not in ['+', '-', '*']:
        stack_list.append(i)
    else:
        a = stack_list.pop()
        b = stack_list.pop()
        stack_list.append(str(eval(b + i + a)))

print(stack_list[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
stak = []
for i in input().split():
    if i in "+-*":
        x = stak.pop()
        y = stak.pop()
        stak.append(str(eval(y + i + x)))
    else:
        stak.append(i)
print(stak.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=[]
for i in input().split():
	if i=='+':
		a[len(a)-2]=int(a[len(a)-2])+int(a[len(a)-1])
		a.pop()
	elif i=='-':
		a[len(a)-2]=int(a[len(a)-2])-int(a[len(a)-1])
		a.pop()
	elif i=='*':
		a[len(a)-2]=int(a[len(a)-2])*int(a[len(a)-1])
		a.pop()
	else :
		a.append(i)

print(a[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
l=[0]*1000
c=0
s=input().split()
for i in s:
	if i=="+":
		l[c-2]=l[c-2]+l[c-1]
		c=c-1
	elif i=="-":
		l[c-2]=l[c-2]-l[c-1]
		c=c-1
	elif i=="*":
		l[c-2]=l[c-2]*l[c-1]
		c=c-1
	else:
		l[c]=int(i)
		c=c+1
print(l[0])

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def push(self, x):
        if self.isFull():
            raise IndexError("stack is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def pop(self):
        if self.isEmpty():
            raise IndexError("pop from empty stack")
        else:
            e = self._l[self._top]
            self._l[self._top] = None
            self._top -= 1
            return e

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

    def isFull(self):
        return self._top == self.n

def poland_calculator(s):
    n = len(s)
    stack = Stack(n)
    i = 0
    while i < n:
        if s[i] == ' ':
            i += 1
            continue
        elif s[i].isdigit():
            sn = ''
            while s[i].isdigit():
                sn += s[i]
                i += 1
            stack.push(int(sn))
        else:
            b = stack.pop()
            a = stack.pop()
            if s[i] == '+':
                e = a + b
            elif s[i] == '-':
                e = a - b
            else:
                e = a * b
            stack.push(e)
            i +=1

    return stack.pop()


if __name__ == '__main__':
    s = input()
    res = poland_calculator(s)
    print(res)

Submission status: Accepted

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

for i in inputs:
    if i.isdigit():
        stack.append(int(i))
    else:
        b = stack.pop()
        a = stack.pop()

        if i == "+":
            ans = a + b
        elif i == "-":
            ans = a - b
        elif i == "*":
            ans = a * b
        elif i == "/":
            ans = a / b

        stack.append(ans)

print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve_operator(left_num, operator, right_num):
    if operator == '+':
        return left_num + right_num
    elif operator == '-':
        return left_num - right_num
    else:
        return left_num * right_num

if __name__ == '__main__':
    stack = []
    for ele in [x for x in input().split()]:
        if ele.isdigit():
            stack.append(int(ele))
        else:
            right_num = stack.pop()
            left_num = stack.pop()
            stack.append(solve_operator(left_num, ele, right_num))
print(stack[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
comands = input().split()
stack = []
for command in comands:
    if command == "+":
        stack = stack[:-2] + [stack[-1] + stack[-2]]
    elif command == "-":
        stack = stack[:-2] + [stack[-2] - stack[-1]]
    elif command == "*":
        stack = stack[:-2] + [stack[-1] * stack[-2]]
    else:
        stack.append(int(command))
assert len(stack) == 1
print(stack[0])

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:
poly = input().split()

stack = []

for _ in poly:

    if _ == '+':
        right = stack.pop()
        left = stack.pop()
        stack.append(left + right)

    elif _ == '-':
        right = stack.pop()
        left = stack.pop()
        stack.append(left - right)

    elif _ == '*':
        right = stack.pop()
        left = stack.pop()
        stack.append(left * right)

    else:
        stack.append(int(_))

print(stack[0])

Submission status: Accepted

Solution code:
# ALDS1_3_A.
# 逆ポーランド記法。

def main():
    A = input().split()
    A.reverse()
    B = []
    # Aを順にpopしていって演算子のときは
    # 手前の二つで演算してその数で置き換える感じ。
    while len(A) > 0:
        op = A.pop()
        if op == '+' or op == '-' or op == '*':
            y = B.pop(); x = B.pop()
            if op == '+': B.append(x + y)
            elif op == '-': B.append(x - y)
            elif op == '*': B.append(x * y)
        else:
            n = int(op); B.append(n)
    print(B[0])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#coding:utf-8

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

string = list(input().split())
num_list = []
for num in string:
    if num in ope:
        b = int(num_list.pop())
        a = int(num_list.pop())
        if num == "+":
            num_list.append(a+b)
        if num == "-":
            num_list.append(a-b)
        if num == "*":
            num_list.append(a*b)
    else:
        num_list.append(num)

print(num_list[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

S = []


def push(x):
    S.append(x)


def pop():
    return S.pop()


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

Submission status: Accepted

Solution code:
def polish(s):
    stack = []
    for x in s:
        if x == "+":
            tmp = stack[-2] + stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        elif x == "-":
            tmp = stack[-2] - stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        elif x == "*":
            tmp = stack[-2] * stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        else:
            stack.append(int(x))
    return stack[0]


s = input().split()

print(polish(s))

Submission status: Accepted

Solution code:
line = input().split()
stack = []
ans = 0
for elem in line:
    if elem in ['+', '-', '*']:

        ele2 = int(stack.pop())
        ele1 = int(stack.pop())
        if elem == '+':
            tmp = ele1 + ele2
        if elem == '-':
            tmp = ele1 - ele2
        if elem == '*':
            tmp = ele1 * ele2
        stack.append(tmp)
    else:
        stack.append(elem)
print(stack[0])

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# initialize stack
Stack = []

A = [i for i in input().split()]

for inputData in A:
    if inputData == "+":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x+y)

    elif inputData == "-":
        y = Stack.pop()
        x = Stack.pop()
        Stack.append(x-y)

    elif inputData == "*":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x*y)

    else:
        Stack.append(int(inputData))

print(Stack[0])

Submission status: Accepted

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    A = list(map(convert, stdinput().split()))
    frame = []
    while len(A) > 0:
        frame.append(A.pop())
        while can_calc(frame):
            v1 = frame.pop()
            v2 = frame.pop()
            op = frame.pop()
            if op == '+':
                frame.append(v1 + v2)
            elif op == '-':
                frame.append(v1 - v2)
            elif op == '*':
                frame.append(v1 * v2)
    print(*frame)

OPERANTS = ('+', '-', '*')
def convert(a):
    if a in OPERANTS:
        return a
    else:
        return int(a)

def can_calc(s):
    if len(s) < 3:
        return False
    else:
        return s[-3] in OPERANTS and type(s[-2]) is int and type(s[-1]) is int

if __name__ == '__main__':
    main()

Submission status: Accepted

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

stack = []

for x in s:
    try:
        t = int(x)
        stack.append(t)
    except:
        a = stack.pop()
        b = stack.pop()
        if x == '+':
            stack.append(a+b)
        elif x == '-':
            stack.append(b-a)
        else:
            stack.append(a*b)

print(stack[0])

Submission status: Accepted

Solution code:
stack = []

for x in input().split():
    try:
        t = int(x)
        stack.append(t)
    except:
        a = stack.pop()
        b = stack.pop()
        if x == '+':
            stack.append(a+b)
        elif x == '-':
            stack.append(b-a)
        else:
            stack.append(a*b)

print(stack[0])

Submission status: Accepted

Solution code:
stack = []

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

print(stack[0])

Submission status: Accepted

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

for i in range(len(arr)):
	current = arr[i]
	if current == '+' or current == '-' or current == '*':
		n1 = stack.pop()
		n2 = stack.pop()
		if current == '+':
			n1 = n1 + n2
		elif current == '-':
			n1 = n2 - n1
		else:
			n1 = n1 * n2
		stack.append(n1)
	else:
		stack.append(int(current))
print(stack.pop())

Submission status: Accepted

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

stack = []

for i in range(len(arr)):
	current = arr[i]
	if current.isnumeric():
		stack.append(int(current))
	else:
		n1 = stack.pop()
		n2 = stack.pop()
		if current == '+':
			n1 = n1 + n2
		elif current == '-':
			n1 = n2 - n1
		else:
			n1 = n1 * n2
		stack.append(n1)

print(stack.pop())

Submission status: Accepted

Solution code:
stack = []
store_num = []
store_result = []

for i,c in enumerate(input().split()): 
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
            
print(stack[-1])

Submission status: Accepted

Solution code:
def main():
    numbers = list(map(str, input().split()))
    stuck = []

    for c in numbers :
        if c == '+':
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(a + b)

        elif c == '-':
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(b - a)

        elif c == '*' :
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(a * b)

        else :
            stuck.append(int(c))

    print(stuck[0])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


arr = [str(s) for s in input().split()]
stack = Stack()
for s in arr:
    if s in ["+", "-", "*"]:
        stack.push(
            eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    else:
        stack.push(int(s))

print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


arr = [str(s) for s in input().split()]
stack = Stack()
# for s in arr:
#     if s in ["+", "-", "*"]:
#         stack.push(
#             eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
#     else:
#         stack.push(int(s))
[stack.push(
    eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1])))) if s in ["+", "-", "*"]
    else stack.push(int(s)) for s in arr]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"]else stack.push(int(s)) for s in arr]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"]else stack.push(int(s))for s in input().split()]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

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

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


stack = Stack()
[stack.push(eval("".join(map(str,[stack.pop(),s,stack.pop()][::-1]))))
 if s in["+","-","*"]else stack.push(int(s))for s in input().split()]
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

    def push(self, x):
        self.top += 1
        self.S[self.top] = x
        return x

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


stack = Stack()
print([stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
       if s in["+", "-", "*"]else stack.push(int(s))for s in input().split()][-1])

Submission status: Accepted

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

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

    def push(self, x):
        self.top += 1
        self.S[self.top] = x
        return x

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


stack = Stack()
print([stack.push(eval("".join(map(str,[stack.pop(),s,stack.pop()][::-1]))))
       if s in["+","-","*"]else stack.push(int(s))for s in input().split()][-1])

Submission status: Accepted

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

if __name__ == '__main__':
    run()

Submission status: Accepted

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


if __name__ == '__main__':
    stack = []
    for item in A:
        if str.isdecimal(item):
            stack.append(int(item))
        else:
            b = stack.pop()
            a = stack.pop()
            if item == "+":
                sum = a + b
                stack.append(sum)
            elif item == "-":
                diff = a - b
                stack.append(diff)
            elif item == "*":
                multi = a * b
                stack.append(multi)
            else:
                print("invalid item")
    print(stack.pop())

Submission status: Accepted

Solution code:
def main():
    exp = [i for i in input().split()]
    stack = []

    for elem in exp:
        if elem.isdigit():
            stack.append(int(elem))
        else:
            n2, n1 = str(stack.pop()), str(stack.pop())
            stack.append(int(eval(n1 + elem + n2)))

    print(stack[0])

main()

Submission status: Accepted

Solution code:
seq=input().strip().split(' ')
mystack=[]
while len(seq) !=0:
    ob=seq.pop(0)
    if ob in ['+','*','-']:
        x = mystack.pop()
        y = mystack.pop()
        if ob =='+':
            mystack.append(y+x)
        elif ob =='*':
            mystack.append(y*x)
        elif ob =='-':
            mystack.append(y-x)
    else :
        mystack.append(int(ob))
print(mystack.pop())

Submission status: Accepted

Solution code:
def ch(x):
    if x in ["+", "-", "*"]:
        return x
    else:
        return int(x)

def calc(x):
    if x[2] == "+":
        return x[0] + x[1]
    elif x[2] == "-":
        return x[0] - x[1]
    elif x[2] == "*":
        return x[0] * x[1]

N = list(map(ch, input().split()))

st = []

while True:
    if len(N) == 0:
        break
    elif (type(N[0]) is int):
        st.append(N[0])
        N.pop(0)
    elif (type(N[0]) is str):
        st[-2] = calc([st[-2],st[-1],N[0]])
        st.pop(-1)
        N.pop(0)
print(*st)

Submission status: Accepted

Solution code:
l = input().split()
m = []
for i in range(len(l)):
    if l[i] == "+":
        m[-2] += m[-1]
        m.pop()
    elif l[i] == "-":
        m[-2] -= m[-1]
        m.pop()
    elif l[i] == "*":
        m[-2] *= m[-1]
        m.pop()
    else:
        m.append(int(l[i]))
print(m[0])