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:
formula_str = input()                                                                                                                                                                                       
formula_splitted = formula_str.split()                                                                                                                                                                      
                                                                                                                                                                                                            
def initialize(List): List[0] = 0                                                                                                                                                                           
                                                                                                                                                                                                            
def IsEmpty(List): List[0] == 0                                                                                                                                                                             
                                                                                                                                                                                                            
def IsFull(List): List[0] >= len(List) - 1                                                                                                                                                                  
                                                                                                                                                                                                            
def push(List, val):                                                                                                                                                                                        
    if IsFull == True: raise ValueError('Full')                                                                                                                                                             
    List[0] += 1                                                                                                                                                                                            
    List[List[0]] = val                                                                                                                                                                                     
                                                                                                                                                                                                            
def pop(List):                                                                                                                                                                                              
    if IsEmpty == True: raise ValueError('Empty')                                                                                                                                                           
    content = List[List[0]]                                                                                                                                                                                 
    List[0] -= 1                                                                                                                                                                                            
    return content                                                                                                                                                                                          
                                                                                                                                                                                                            
formula = [0 for i in range(0, len(formula_splitted) + 1)]                                                                                                                                                  
for content in formula_splitted:                                                                                                                                                                            
    if content == '*':                                                                                                                                                                                      
        val1, val2 = pop(formula), pop(formula)                                                                                                                                                             
        push(formula, val2 * val1)                                                                                                                                                                          
    elif content == '+':                                                                                                                                                                                    
        val1, val2 = pop(formula), pop(formula)                                                                                                                                                             
        push(formula, val2 + val1)                                                                                                                                                                          
    elif content == '-':                                                                                                                                                                                    
        val1, val2 = pop(formula), pop(formula)                                                                                                                                                             
        push(formula, val2 - val1)                                                                                                                                                                          
    else:                                                                                                                                                                                                   
        push(formula, int(content))                                                                                                                                                                         
                                                                                                                                                                                                            
print(pop(formula))

Submission status: Accepted

Solution code:
# coding: utf-8
num = []
for ch in input().rstrip().split():
    if ch.isdigit():
        num.append(int(ch))
    else:
        a = num.pop()
        b = num.pop()
        if ch == "+":
            num.append(b + a)
        elif ch == "-":
            num.append(b - a)
        elif ch == "*":
            num.append(b * a)
        else:
            num.append(b / a)
print(num[0])

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
class Stack:
    def __init__(self):
        self.elements = []
    
    def push(self, element):
        self.elements.append(element)
    
    def pop(self):
        item = self.elements[-1]
        del self.elements[-1]
        return item

def putsarray(array):
    if len(array) == 0:
        return
    for i in range(len(array) - 1):
        print(array[i], end=' ')
    print(array[-1])

def get_operands(st):
    # オペランドの順番は逆に格納されている
    op2 = st.pop()
    op1 = st.pop()
    return op1, op2

if __name__ == "__main__":
    st = Stack()
    array = input().split()
    for symbol in array:
        if symbol == "*":
            op1, op2 = get_operands(st)
            st.push(op1 * op2)
        elif symbol == "+":
            op1, op2 = get_operands(st)
            st.push(op1 + op2)
        elif symbol == "-":
            op1, op2 = get_operands(st)
            st.push(op1 - op2)
        else:
            st.push(int(symbol))
    print(st.pop())

Submission status: Accepted

Solution code:
S = []

for x in input().split():
    if x == "+":
        S[-2] = S[-2] + S[-1]
        S.pop(-1)
    elif x == "-":
        S[-2] = S[-2] - S[-1]
        S.pop(-1)
    elif x == "*":
        S[-2] = S[-2] * S[-1]
        S.pop(-1)
    else:
        S.append(int(x))

print(*S)

Submission status: Accepted

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

stack = []
for b in buff:
    try:
        num = int(b)
        stack.append(num)
    except ValueError:
        op = b
        right = stack.pop()
        left = stack.pop()
        if op == '+':
            res = left + right
        elif op == '-':
            res = left - right
        else:
            res = left * right
        stack.append(res)

print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=[]
for e in input().split():
 s+=[str(eval(s.pop(-2)+e+s.pop()))if e in"+-*"else e]
print(*s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L = list(input().split())
numstack = []
for item in L:
    if item == '+':
        tmp = numstack.pop() + numstack.pop()
        numstack.append(tmp)
    elif item == '-':
        tmp = - numstack.pop() + numstack.pop()
        numstack.append(tmp)
    elif item == '*':
        tmp = numstack.pop() * numstack.pop()
        numstack.append(tmp)
    else:
        numstack.append(int(item))
print(numstack[-1])

Submission status: Accepted

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

stack = []

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

print(stack[0])

Submission status: Accepted

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

stack = []

for ch in a:
    if ch in ['+', '-', '*']:
        b = int(stack.pop())
        a = int(stack.pop())

        if ch == '+':   stack.append(a+b)
        elif ch == '-': stack.append(a-b)
        else:           stack.append(a*b)
    else:   stack.append(ch)

print(stack[0])

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, size=200):
        self.size = size
        self.data = []
        self.pointer = -1
    
    def push(self, x):
        self.pointer += 1
        self.data.insert(self.pointer, x)
    
    def pop(self):
        ret = self.data[self.pointer]
        self.pointer -= 1
        return ret
    
    def isEmpty(self):
        return len(self.data[:self.pointer + 1]) == 0
    
    def isFull(self):
        return len(self.data) == self.size

def isNumber(s):
    return s.isdigit()

def calc(arg1, arg2, op):
    if (op == '+'):
        return arg1 + arg2
    elif (op == '-'):
        return arg1 - arg2
    elif (op == '*'):
        return arg1 * arg2

IN = input().split()
stack = Stack()
for input_str in IN:
    if isNumber(input_str):
        stack.push(int(input_str))
    else:
        op = input_str
        arg2 = stack.pop()
        arg1 = stack.pop()
        stack.push(calc(arg1, arg2, op))

print(stack.pop())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 10:00:00 2019

@author: Yamazaki Kenichi
"""

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

q=[]
for i in range(len(A)):
    if str.isdecimal(A[i]):
        q.append(int(A[i]))
    elif A[i] == '+':
        q.append(q.pop()+q.pop())
    elif A[i] == '-':
        q.append(-(q.pop()-q.pop()))
    elif A[i] == '*':
        q.append(q.pop()*q.pop())
print(q.pop())

Submission status: Accepted

Solution code:
from collections import deque

ope={'+':lambda a,b:b+a,'-':lambda a,b:b-a,'*':lambda a,b:b*a}

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

n=len(A)
D=deque()
for i in A:
    if i not in ope:
        D.append(i)
    else:
        D.append(ope[i](int(D.pop()),int(D.pop())))

print(D.pop())

Submission status: Accepted

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

for i in a:
    if i.isdigit():
        b.append(i)
    else:
        ans = str(eval(b.pop(len(b)-2) + i + b.pop()))
        b.append(ans)
    #print(b)
print(b.pop())

Submission status: Accepted

Solution code:
x = input().split()
a = []
for i, j in enumerate(x):
    if j == "+":
        a[-2] += a[-1]
        a.pop()
    elif j == "-":
        a[-2] -= a[-1]
        a.pop()
    elif j == "*":
        a[-2] *= a[-1]
        a.pop()
    else:
        a.append(int(j))
print(a[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! python3
# stack.py - ポーランド記法で記述された計算式を解くプログラム

# 必要な変数を定義する
stack = [None] # 空の配列、0番目は埋まっている
# top = 0  # 配列の中の、一番うしろの値、初期状態では0
MAX = 201  # 配列が持つことができる最大値

# 配列が空かどうかを判定する（真偽値を返す）
def isEmpty(top):
    return top == 0

# 配列がいっぱいになっているかどうかを判定する（真偽値を返す）
def isFull(top):
    return top >= MAX - 1

# 配列の一番うしろに値を追加する
def push(x, stack):
    if isFull(len(stack)):
        raise Exception  # オーバーフロー
    stack.append(x)
    return stack

# 配列の一番うしろから値を削除する
def pop(stack):
    if isEmpty(len(stack)):
        raise Exception  # アンダーフロー
    stack = stack.pop()
    return stack

# 入力を扱う
original_input_list = input().split(' ')
input_list = []
for items in original_input_list:
    if items.isdecimal():
        input_list.append(int(items))
    else :
        input_list.append(items)

# print(input_list)        

for items in input_list:
    if type(items) == int:
        push(items, stack)
    elif items == "+":
        first_digit = pop(stack)
        second_digit = pop(stack)
        calculated_digit = second_digit + first_digit
        push(calculated_digit, stack)
    elif items == "-":
        first_digit = pop(stack)
        second_digit = pop(stack)
        calculated_digit = second_digit - first_digit
        push(calculated_digit, stack)
    elif items == "*":
        first_digit = pop(stack)
        second_digit = pop(stack)
        calculated_digit = second_digit * first_digit
        push(calculated_digit, stack)
    elif items == "/":
        first_digit = pop(stack)
        second_digit = pop(stack)
        calculated_digit = second_digit / first_digit
        push(calculated_digit, stack)

# print(stack)
# print(first_digit)
# print(second_digit)
print(stack[-1])

Submission status: Accepted

Solution code:
symbol = input().rstrip().split()
stack = []
operator = ['+', '-', '*']

for s in symbol:
    if s not in operator:
        stack.append(int(s))
    else:
        b = stack.pop(-1)
        a = stack.pop(-1)
        if s == '+':
            stack.append(a + b)
        elif s == '*':
            stack.append(a * b)
        else:
            stack.append(a - b)

print(stack[0])

Submission status: Accepted

Solution code:
from sys import stdin
from queue import LifoQueue

exps = stdin.readline().rstrip().split()

stc = LifoQueue()
for i in exps:
    if i == "+":
        b = stc.get()
        a = stc.get()
        stc.put(a+b)
    elif i == "-":
        b = stc.get()
        a = stc.get()
        stc.put(a-b)
    elif i == "*":
        b = stc.get()
        a = stc.get()
        stc.put(a*b)
    else:
        stc.put(int(i))

print(stc.get())

Submission status: Accepted

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

def stackcalc(S):
    now = S.pop()
    if now == '+':
        return stackcalc(S) + stackcalc(S)
    elif now == '-':
        return -(stackcalc(S) - stackcalc(S))
    elif now == '*':
        return stackcalc(S) * stackcalc(S)
    elif now == '/':
        return stackcalc(S) / stackcalc(S)
    else:
        return int(now)


print(stackcalc(B))

Submission status: Accepted

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

t = []

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

Submission status: Accepted

Solution code:
stack = []
top = 0
def push(a):
    global top
    stack[top] = a
    top += 1 

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


if __name__ == '__main__':
    stack.extend(range(0,10000,1))
    s = str(input()).split()
    for c in s:
        #print(stack)
        if c == '+':
            push((pop())+pop())
        elif c == '-':
            push((-pop())+pop())
        elif c == '*':
            push(pop()*pop())
        else:
            push(int(c))
    print(pop())

Submission status: Accepted

Solution code:
import sys
import operator

operators = {
    '+': operator.add,
    '-': operator.sub,
    '*': operator.mul
}

stack = []


def push(v):
    stack.append(v)


def operate(op):
    right = stack.pop()
    left = stack.pop()
    stack.append(op(left, right))


for sym in sys.stdin.read().strip().split():
    op = operators.get(sym)
    if op:
        operate(op)
    else:
        push(int(sym))

print(stack.pop())

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
#  Stack : python3
#  2018.11.26 yonezawa

from collections import deque
import sys
input = sys.stdin.readline

def calc(q):
    tq = deque()
    for i in range(len(q)):
        op = q.popleft()
#        print ("debug:",op)
        if ( op == '+' ):
            a = tq.pop()
            b = tq.pop()
            tq.append(b+a)
        elif (op == '-' ):
            a = tq.pop()
            b = tq.pop()
            tq.append(b-a)

        elif (op == '*' ):
            a = tq.pop()
            b = tq.pop()
            tq.append(b*a)
        elif (op == '/' ):
            a = tq.pop()
            b = tq.pop()
            tq.append(b//a)
        else:
            tq.append(int(op))
    return tq.pop()

def main():
    q = deque(map(str,input().split()))
    print (calc(q))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
stack
"""
from collections import deque

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

stack = deque()
for i in range(len(aN)):
    if aN[i] in ('+', '-', '*'):
        b = stack.pop()
        a = stack.pop()
        stack.append(str(eval(a + aN[i] + b)))
    else:
        stack.append(aN[i])
print(stack.pop())

Submission status: Accepted

Solution code:
n=input()
m=n.split(" ")
a=[]
k=0
for i in m:
    if i!="+" and i!="-" and i!="*" :
        z=int(i)
        a.append(z)
    
    else :
        if i=="+":
                k=a.pop()+a.pop()
                a.append(k)
        elif i=="-":
                k=a.pop(-2)-a.pop()
                a.append(k)
        else:
            k=a.pop()*a.pop()
            a.append(k)
print(a.pop())

Submission status: Accepted

Solution code:
f = input().rstrip().split()
stack = []
for i in f:
    if i == "+":
        l = len(stack)
        a = stack.pop(l - 2) + stack.pop(l - 2)
        stack.append(a)
    elif i == "-":
        l = len(stack)
        a = stack.pop(l - 2) - stack.pop(l - 2)
        stack.append(a)
    elif i == "*":
        l = len(stack)
        a = stack.pop(l - 2) * stack.pop(l - 2)
        stack.append(a)
    else:
        j = int(i)
        stack.append(j)
print(stack[0])

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_A


def solve():
    stack = []
    equations = list(map(str, input().split()))

    for equ in equations:
        try:
            num = int(equ)
            stack.append(num)
        except Exception:
            a = stack.pop()
            b = stack.pop()
            stack.append(int(eval('{} {} {}'.format(b, equ, a))))
    print(stack.pop())


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
word = input().strip().split(" ")
ans = []
t = 0
for i in range(len(word)):
    if word[i] == "+":
        s = ans.pop()
        t = ans.pop()
        ans.append(t+s)
    elif word[i] == "-":
        s = ans.pop()
        t = ans.pop()
        ans.append(t-s)
    elif word[i] == "*":
        s = ans.pop()
        t = ans.pop()
        ans.append(t*s)
    else:
        ans.append(int(word[i]))
print(ans[0])

Submission status: Accepted

Solution code:
words = input().strip().split(' ')
num = []
for i in range(len(words)):
    word = words[i]
    if word == "+":
        num.append(num.pop() + num.pop())
    elif word == "-":
        num.append(-(num.pop() - num.pop()))
    elif word == "*":
        num.append(num.pop() * num.pop())
    else:
        num.append(int(word))
print(num[0])

Submission status: Accepted

Solution code:
data=[]
for num in input().split():
    a=0
    b=0
    if num is "+":
        a=data.pop()
        b=data.pop()
        data.append(b+a)
    elif num is "-":
        a=data.pop()
        b=data.pop()
        data.append(b-a)
    elif num is "*":
        a=data.pop()
        b=data.pop()
        data.append(b*a)
    else:
        data.append(int(num))
print(data.pop())

Submission status: Accepted

Solution code:
import sys

def GetReadlineData():
    readlinedata= sys.stdin.readline()
    splitdata = [i for i in readlinedata.split()]
    
    return splitdata
            
def CalcShapingData(splitdata):

    calcresult = [0 for i in range(len(splitdata))]

    j = 0
    for i in range(0, len(splitdata)):
        if splitdata[i].isdecimal():
            j = j + 1
            calcresult[j] = int(splitdata[i])
            result = int(splitdata[i])
            #if j == 2:
                #print('{}:{}'.format(j,calcresult[j]))
        else:
            #print(splitdata[i])
            if splitdata[i] == '+':
                result = calcresult[j-1] + calcresult[j]
                #print(calcresult[j-2])
                #print(calcresult[j-1])
                #print(result)
                j = j - 1
            elif splitdata[i] == '-':
                result = calcresult[j-1] - calcresult[j]
                #print(calcresult[j-1])
                #print(calcresult[j])
                #print(result)
                j = j - 1
            elif splitdata[i] == '*':
                result = calcresult[j-1] * calcresult[j]
                #print(calcresult[j-1])
                #print(calcresult[j])
                #print(result)
                j = j - 1
            elif splitdata[i] == '/':
                result = int(calcresult[j-1]) / int(calcresult[j])
                #print(result)
                j = j -1
            
            #calcresult.pop(j-1)
            #calcresult.pop(j)
            #print(j)
            calcresult[j] = result

    for k in range(1,j):
        calcresult.pop(k)

    return result


def main():
    splitdata = GetReadlineData()
    result = CalcShapingData(splitdata)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = list(map(str, input().split(" ")))
op = {"+":lambda x, y:x+y, "-":lambda x,y:x-y, "*":lambda x,y:x*y}
stack = []

for i, z in enumerate(A):
    if z not in op:
        stack.append(z)
        continue
    y = int(stack.pop())
    x = int(stack.pop())
    stack.append(op[z](x,y))
print(stack[0])

Submission status: Accepted

Solution code:

A = list(map(str, input().split()))
B = []

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

print(B[0])

Submission status: Accepted

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

nlist = []

for c in command:
    if c == "+":
        ans = nlist[-2] + nlist[-1]
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)
    elif c == "-":
        ans = nlist[-2] - nlist[-1]
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)
    elif c == "*":
        ans = nlist[-2] * nlist[-1]
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)
    else:
        nlist.append(int(c))

print(nlist[0])

Submission status: Accepted

Solution code:
x = input().split()
# x = ['1', '2', '+', '3', '4', '-', '*']

s = []
for i in range(len(x)):
    if x[i] == '+':
        a = int(s[-1])+int(s[-2])
        del s[-2:]
        s.append(a)
    elif x[i] == '-':
        b = int(s[-2])-int(s[-1])
        del s[-2:]
        s.append(b)
    elif x[i] == '*':
        c = int(s[-1])*int(s[-2])
        del s[-2:]
        s.append(c)
    else:
        s.append(x[i])

print(s[0])

Submission status: Accepted

Solution code:
stack=[]
data=input().split()
for str in data:
    if(str =='+'):
        stack.append(stack.pop()+stack.pop())
    elif(str =="-"):
        stack.append(-stack.pop()+stack.pop())
    elif(str =="*"):
        stack.append(stack.pop()*stack.pop())
    else:
        stack.append(int(str))
print(stack[0])

Submission status: Accepted

Solution code:
line = list(map(str,input().split()))
s = []
operand_list = ['+','-', '*']
for i in range(len(line)):
    if line[i] not in operand_list:
        s.append(int(line[i]))
    elif line[i] is '+':
        ans = s[-1] + s[-2]
        s.pop()
        s.pop()
        s.append(ans)
    elif line[i] is '-':
        ans = s[-2] - s[-1]
        s.pop()
        s.pop()
        s.append(ans)
    elif line[i] is '*':
        ans = s[-1] * s[-2]
        s.pop()
        s.pop()
        s.append(ans)
print(s[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_stack = [0]
list_input = list((map(str, input().split())))
i = 0
while True:
    try:
        list_stack.append(int(list_input[i]))
    except ValueError:
        b = list_stack.pop()
        a = list_stack.pop()
        if list_input[i] == "+":
            list_stack.append(int(a + b))
        elif list_input[i] == "-":
            list_stack.append(int(a-b))
        else:
            list_stack.append(int(a*b))

    try:
        i += 1
        list_input[i]
    except IndexError:
        print(list_stack.pop())
        break

Submission status: Accepted

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

print(a.pop())

Submission status: Accepted

Solution code:
line=input()
operands=line.split(' ')
poland=[]
while operands:
    if operands[0]=='+' or operands[0]=='-' or operands[0]=='*':
        x=int(poland.pop())
        y=int(poland.pop())
        operand=operands.pop(0)
        if operand=='+':
            poland.append(y+x)
        elif operand=='-':
            poland.append(y-x)
        elif operand=='*':
            poland.append(y*x)
    else:
        poland.append(operands.pop(0))
print(str(poland.pop()))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

top = 0
S = [0] * 1000


def push(x):
    global top
    top += 1
    S[top] = x


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


expr = input().split()
for s in expr:
    if s == '+':
        a = pop()
        b = pop()
        push(b + a)
    elif s == '-':
        a = pop()
        b = pop()
        push(b - a)
    elif s == '*':
        a = pop()
        b = pop()
        push(b * a)
    elif s == '/':
        a = pop()
        b = pop()
        push(b / a)
    else:
        push(int(s))

print(pop())