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 doc_string():
    """
    I can fly.
    """

list = []
stack = []
if __name__ == "__main__":
    list = raw_input().split()

    for var in list:
        try:
            stack.append(int(var))
        except:
            if var == "+":
                a = stack.pop()
                b = stack.pop()
                stack.append(b + a)
            if var == "-":
                a = stack.pop()
                b = stack.pop()
                stack.append(b - a)
            if var == "*":
                a = stack.pop()
                b = stack.pop()
                stack.append(b * a)

    print stack.pop()

Submission status: Accepted

Solution code:
# encoding: utf-8

input = raw_input().split()

stack = []
for n in input:
    if(n.isdigit()):
        stack.append(int(n))
    else:
        a = stack.pop()
        b = stack.pop()
        if n == '+':
            stack.append(b + a)
        elif n == '-':
            stack.append(b - a)
        elif n == '*':
            stack.append(b * a)
        else:
            stack.append(b / a)
print stack.pop()

Submission status: Accepted

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

    def push(self,v):
        self.values.append(v)

    def pop(self):
        if len(self.values) == 0:
            raise
        else:
            v = self.values[len(self.values)-1]
            del self.values[len(self.values)-1]
            return v

symbols = raw_input().split(' ')

stack = Stack()
for s in symbols:
    if not s in ['+', '-', '*']:
        stack.push(s)
    else:
        v1 = int(stack.pop())
        v2 = int(stack.pop())
        if s == '+':
            stack.push(v1+v2)
        elif s == '-':
            stack.push(v2-v1)
        elif s == '*':
            stack.push(v1*v2)

print stack.pop()

Submission status: Accepted

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

print (stack[0])

Submission status: Accepted

Solution code:
input_line = [str(s) for s in input().split()]
input_line = input_line[::-1]
tmp_number = []
while(len(input_line) != 0):
    tmp = input_line[-1]
    if tmp == "+":
        tmp_number[-2] = tmp_number[-2] + tmp_number[-1]
        tmp_number.pop()
    elif tmp == "-":
        tmp_number[-2] = tmp_number[-2] - tmp_number[-1]
        tmp_number.pop()
    elif tmp == "*":
        tmp_number[-2] = tmp_number[-2] * tmp_number[-1]
        tmp_number.pop()
    else:
        tmp_number.append(int(tmp))
    input_line.pop()
print(tmp_number[0])

Submission status: Accepted

Solution code:
a = input()
a = a.split(' ')
stack = []
for i in a:
    if i == '+' or i == '-' or i == '*':
        s = int(stack.pop())
        t = int(stack.pop())
        if i == '+':
            u = t + s
        if i == '-':
            u = t - s
        if i == '*':
            u = t * s
        stack.append(u)
    else:
        stack.append(i)

print(stack.pop())

Submission status: Accepted

Solution code:
s = []
F = {
    '+': lambda: s.append(s.pop() + s.pop()),
    '-': lambda: s.append(-s.pop() + s.pop()),
    '*': lambda: s.append(s.pop() * s.pop())
}

for op in input().split():
    if op in F:
        F[op]()
    else:
        s.append(int(op))

print(s.pop())

Submission status: Accepted

Solution code:
in_l = [a for a in input().split()]
stack = []

while len(in_l) > 0:
    i_e = in_l.pop(0)

    if not i_e in "+-*/":
        stack.append(int(i_e))

    else:
        tmp1 = stack.pop(len(stack)-1)
        tmp2 = stack.pop(len(stack)-1)
        if i_e == '+':
            stack.append(tmp2+tmp1)
        elif i_e == '-':
            stack.append(tmp2-tmp1)
        elif i_e == '*':
            stack.append(tmp2*tmp1)
        elif i_e == '/':
            stack.append(tmp2/tmp1)

print(stack.pop(0))

Submission status: Accepted

Solution code:
from collections import deque

def main():
    S = raw_input().split()
    D = deque([])
    for s in S:
        if s == '+':
            b = D.pop()
            a = D.pop()
            D.append(a+b)   
        elif s == '-':
            b = D.pop()
            a = D.pop()
            D.append(a-b)
        elif s == '*':
            b = D.pop()
            a = D.pop()
            D.append(a*b)
        else:
            D.append(int(s))
    print D.pop()
    return 0

main()

Submission status: Accepted

Solution code:
stack = []
for s in input().split():
    if s.isdigit():
        stack.append(s)
    else:
        y, x = (stack.pop() for _ in range(2))
        stack.append(str(eval(x + s + y)))
print(stack.pop())

Submission status: Accepted

Solution code:
def stack(A):
    stack = []
    for opr in A:
        if opr.isdigit():
            stack.append(opr)
        else:
            opr1 = stack.pop()
            opr2 = stack.pop()
            stack.append(str(eval(opr2 + opr + opr1)))
    print stack.pop()

if __name__ == "__main__":
    A = raw_input().split()
    stack(A)

Submission status: Accepted

Solution code:
S = []

A = raw_input().split()

for i in range(len(A)):
    if A[i] == '+':
        S.append(int(S.pop()) + int(S.pop()))
    elif A[i] == '-':
        S.append(-int(S.pop()) + int(S.pop()))
    elif A[i] == '*':
        S.append(int(S.pop()) * int(S.pop()))
    else:
        S.append(A[i])

print S[0]

Submission status: Accepted

Solution code:

Stack=[]
def push(x):
    Stack.append(x)

def pop():
    return Stack.pop()

def solve():
    s_list=raw_input().split()
    for i in range(len(s_list)):
        if s_list[i]=='+':
            b=pop()
            a=pop()
            push(a+b)
        elif s_list[i]=='-':
            b=pop()
            a=pop()
            push(a-b)
        elif s_list[i]=='*':
            b=pop()
            a=pop()
            push(a*b)
        else:
            push(int(s_list[i]))
    print(pop())

def main():
    if __name__=="__main__":
        solve()

main()

Submission status: Accepted

Solution code:
n=map(str,raw_input().split())
a=[]
ai=0
for i in n:
    if i=="+" :
        a.append(a[ai-1]+a[ai-2])
        a.pop(ai-1);a.pop(ai-2)
        ai-=1
    elif i=="-":
        a.append(a[ai-2]-a[ai-1])
        a.pop(ai-1);a.pop(ai-2)
        ai-=1
    elif i=="*":
        a.append(a[ai-1]*a[ai-2])
        a.pop(ai-1);a.pop(ai-2)
        ai-=1
    else:
        a.append(int(i))
        ai+=1
print(a[0])

Submission status: Accepted

Solution code:
x = raw_input().split()
s = []
for e in x:
    try:
        s.append(int(e))
    except:
        b = s.pop()
        a = s.pop()
        if e == '+':
            s.append(a+b)
        if e == '-':
            s.append(a-b)
        if e == '*':
            s.append(a*b)
print s.pop()

Submission status: Accepted

Solution code:
class Node(object):
    def __init__(self, c):
        self.c = c
        self.left = None
        self.right = None

def print_node(node):
    print node.c
    if node.left != None:
        print_node(node.left)
    if node.right != None:
        print_node(node.right)

def calc_node(node):
    if node.c in ('+', '-', '/', '*'):
        if node.c == '+':
            return calc_node(node.left) + calc_node(node.right)
        if node.c == '-':
            return calc_node(node.left) - calc_node(node.right)
        if node.c == '*':
            return calc_node(node.left) * calc_node(node.right)
    else:
        return int(node.c)

def make_node(s):
    global pos
    node = Node(s[pos])
    if s[pos] in ('+', '-', '*'):
        pos += 1
        node.right = make_node(s)
        pos += 1
        node.left = make_node(s)
    return node

s = raw_input().split()
s.reverse()
#print s
pos = 0
n = make_node(s)
#print_node(n)
print "%d" % calc_node(n)

Submission status: Accepted

Solution code:
ope = {"+": lambda a, b: b + a,
	   "-": lambda a, b: b - a,
	   "*": lambda a, b: b * a}
stack = []

for c in input().split():
	if c in ope:
		stack.append(ope[c](stack.pop(), stack.pop()))
	else:
		stack.append(int(c))

print(stack[-1])

Submission status: Accepted

Solution code:
def push(x):
	global stack

	stack.append(x)

def pop():
	global stack

	ret = stack.pop()
	return ret

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

if __name__ == '__main__':
	stack = []

	for c in input().split():
		if c in ope:
			push(ope[c](pop(), pop()))
		else:
			push(int(c))

	print(" ".join(map(str, stack)))

Submission status: Accepted

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

list = map(str, raw_input().split())
num = []
for i in list:
    if i == '+':
        num[len(num)-2] += num.pop()
    elif i == '-':
        num[len(num)-2] -= num.pop()
    elif i == '*':
        num[len(num)-2] *= num.pop()
    else:
        num.append(int(i))
print num[0]

Submission status: Accepted

Solution code:
l = input().split()
stack = []
for op in l:
    if op.isdigit():
        stack.append(int(op))
    elif op == '+':
        stack.append(stack.pop() + stack.pop())
    elif op == '-':
        stack.append(- stack.pop() + stack.pop())
    elif op == '*':
        stack.append(stack.pop() * stack.pop())
print(stack[-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
class mystack:
  v = [0 for i in range(222)]
  t = 0

  def push(self,a):
    self.t += 1
    self.v[self.t] = a
  def pop(self):
    self.t -= 1
  def top(self):
    return self.v[self.t]
  def pr(self):
    for i in range(1, self.t+1):
      sys.stdout.write(self.v[i] + " ")
    sys.stdout.write('\n')

s = mystack()
l = sys.stdin.readline().split()

for i in l:
  if not i.isdigit():
    a = s.top()
    s.pop()
    b = s.top()
    s.pop()
    if i == '+':
      s.push(b+a)
    if i == '-':
      s.push(b-a)
    if i == '*':
      s.push(b*a)
  else:
    s.push(int(i))

print(s.top())

Submission status: Accepted

Solution code:
s = raw_input()
l = s.split(' ')
stk = []

for i in l:
  if i in ['+','-','*','/']:
    b = stk.pop()
    a = stk.pop()
    if i == '+':
      c = a+b
      stk.append(c)
    elif i == '-':
      c = a-b
      stk.append(c)
    elif i == '*':
      c = a * b
      stk.append(c)
    elif i == '/':
      c = a / b
      stk.append(c)
  else:
    stk.append(int(i))
print stk[0]

Submission status: Accepted

Solution code:
operands = ["+","-","*"]
symbols = raw_input().split()
ans = 0
i = 0
while True:
    if len(symbols) == 1:
        break
    if symbols[i] in operands:
        a = int(symbols.pop(i-2))
        b = int(symbols.pop(i-2))
        o = symbols.pop(i-2)
        if o == "*":
            symbols.insert(i-2,a*b)
        elif o == "+":
            symbols.insert(i-2,a+b)
        elif o == "-":
            symbols.insert(i-2,a-b)
        else:
            "This operand is invalid."
            break
        i-=1
    else:
        i+=1
print symbols[0]

Submission status: Accepted

Solution code:
rpn = map(str, raw_input().split())
stack = []

for i in rpn:
    if i.isdigit():
        stack.append(i)
    else:
        n1 = int( stack.pop() )
        n2 = int( stack.pop() )

    if   i == '+':
        stack.append( str(n2+n1) )
    elif i == '-':
        stack.append( str(n2-n1) )
    elif i == '*':
        stack.append( str(n2*n1) )

print stack[0]

Submission status: Accepted

Solution code:
form = input().split()
s = []
for c in form:
    if c in "+-*":
        s.append(str(eval( "{2} {0} {1}".format(c,s.pop(),s.pop()) )))
    else:
        s.append(c)
print(s[0])

Submission status: Accepted

Solution code:
import re

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

for elem in data:
    if re.match('\d+', elem):
        stack.append(int(elem))
    else:
        a = stack.pop()
        b = stack.pop()
        if elem == "+":
            stack.append(b+a)
        elif elem == "-":
            stack.append(b-a)
        elif elem == "*":
            stack.append(b*a)

print(stack[0])

Submission status: Accepted

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

operators = {"+": lambda x, y: x + y,
             "-": lambda x, y: x - y,
             "*": lambda x, y: x * y,
             "/": lambda x, y: float(x) / y}


def calculation(A):
    stack = []

    for i in xrange(len(A)):
        if isinstance(A[i], str):
            op_right = stack.pop()
            op_left = stack.pop()
            stack.append(operators[A[i]](op_left, op_right))
        elif isinstance(A[i], int):
            stack.append(int(A[i]))
    return stack[-1]

if __name__ == '__main__':
    A = raw_input().split()
    # A = [1, 2, '+', 3, 4, '-', '*']
    for i in xrange(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print calculation(A)

Submission status: Accepted

Solution code:
shiki = input().split(' ')
stack = [];

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

print(stack.pop())

Submission status: Accepted

Solution code:
class Node:
    def __init__(self,v):
        self.v = v
        self.next = None


class Stack:
    def __init__(self):
        self.head = None
    def push(self,v):
        n = Node(v)
        n.next = self.head
        self.head = n
    def pop(self):
        if self.head == None:
            return None
        n = self.head
        self.head = self.head.next
        return n.v

ops = raw_input().split(' ')

s = Stack()
for op in ops:
    if op == '+':
        a = s.pop()
        b = s.pop()
        s.push(a+b)
    elif op == '-':
        a = s.pop()
        b = s.pop()
        s.push(b-a)
    elif op == '*':
        a = s.pop()
        b = s.pop()
        s.push(a*b)
    else:
        num = int(op)
        s.push(num)

print s.pop()

Submission status: Accepted

Solution code:
input_ = raw_input().split()

stack = []
for s in input_:
    if s.isdigit():
        stack.append(s)
    else:
        x = stack.pop()
        y = stack.pop()
        ans = eval(y + s + x)
        stack.append(str(ans))
        
print stack[0]

Submission status: Accepted

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

while True:
    if len(array) == 0: break
    e = array.pop(0)
    if e.isdigit():
        stack.append(e)
    else:
        num1 = stack.pop()
        num2 = stack.pop()
        stack.append(str(eval(num2 + e + num1)))

print(stack[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding:utf-8
# Reverse Polish Notation

def main():
    RPM = input().split()
    stack = []
    operator = ['+', '-', '*']
    
    while len(RPM) > 0:
        value = RPM.pop(0)
        if value not in operator:
            stack.append(value)
        else:
            x, y = str(stack.pop()), str(stack.pop())
            stack.append(eval(y + value + x))
    
    print(stack[0])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    def pop(self):
        return self.stack.pop(-1)

def calc(array):
    stack = Stack()
    for s in array:
        if s.isdigit():
            stack.push(int(s))
        else:
            o2 = stack.pop()
            o1 = stack.pop()
            ans = 0
            if s == '+':
                ans = o1 + o2
            elif s == '-':
                ans = o1 - o2
            elif s == '*':
                ans = o1 * o2
            elif s == '/':
                ans = o1 / o2
            stack.push(ans)
    return stack.pop()


def main():
    in_arr = input().split()
    print(calc(in_arr))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def arg(operator):
    try:
        return elements.index(operator)
    except:
        return 100000000000000


elements = [elem if elem in ['+', '-', '*']
            else int(elem) for elem in input().split()]

while len(elements) != 1:
    if arg('+') or arg('-') or arg('*'):
        i = arg('+')
        i = min(i, arg('-'))
        i = min(i, arg('*'))

        if elements[i] == '+': r = elements[i-2] + elements[i-1]
        elif elements[i] == '-': r = elements[i-2] - elements[i-1]
        elif elements[i] == '*': r = elements[i-2] * elements[i-1]

        # i, i-1, i-2 -> one element
        elements = elements[:i-2] + [r] + elements[i+1:]
    else:
        break

print(elements[0])

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

stack = []

f = input().split()

for s in f:
    if s in ('+', '-', '*'):
        stack.append(str(eval("{1}{2}{0}".format(stack.pop(), stack.pop(), s))))
    else:
        stack.append(s)

print(*stack)

Submission status: Accepted

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

Submission status: Accepted

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

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print(str(s[0]))

Submission status: Accepted

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

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print(str(s[0]))

Submission status: Accepted

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

for lt in exp:
    if lt == '+' or lt == '-' or lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        if lt == '+':
            s.append(lhs + rhs)
        if lt == '*':
            s.append(lhs * rhs)
        if lt == '-':
            s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print(str(s[0]))

Submission status: Accepted

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

for lt in exp:
    if lt.isdigit():
        s.append(int(lt))
    else:
        rhs = s.pop()
        lhs = s.pop()
        if lt == '+':
            s.append(lhs + rhs)
        if lt == '*':
            s.append(lhs * rhs)
        if lt == '-':
            s.append(lhs - rhs)
        
print(str(s[0]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding:utf-8
# Reverse Polish Notation

def main():
    RPM = input().split()
    stack = []
    operator = ['+', '-', '*']
    
    while len(RPM) > 0:
        value = RPM.pop(0)
        if value not in operator:
            stack.append(value)
        else:
            x, y = str(stack.pop()), str(stack.pop())
            stack.append(eval(y + value + x))
    
    print(stack[0])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ts = input().split(" ")
stack = []
for t in ts:
    if t not in ("-", "+", "*"):
        stack.append(int(t))
    else:
        n2 = stack.pop()
        n1 = stack.pop()
        if t == "-":
            stack.append(n1 - n2)
        elif t == "+":
            stack.append(n1 + n2)
        else:
            stack.append(n1 * n2)
print(stack.pop())

Submission status: Accepted

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


ans = []
for i in rows:
    if i == "+":
        a = ans.pop()
        b = ans.pop()
        ans.append(a + b)
    elif i == "-":
        a = ans.pop()
        b = ans.pop()
        ans.append(b - a)
    elif i == "*":
        a = ans.pop()
        b = ans.pop()
        ans.append(a * b)
    else:
        ans.append(int(i))

print(' '.join(map(str, ans)))

Submission status: Accepted

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

for e in l:
    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

class Stack:
    def __init__(self, max):
        self.max = max
        self.stack = list(range(max))
        self.top = 0

    def push(self, value):
        if self.top == self.max:
            raise IndexError('?????????????????????????????????')

        self.stack[self.top] = value
        self.top += 1

    def pop(self):
        if self.top == 0:
            raise IndexError('??????????????????????????¨??????')

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

def main():
    expr = sys.stdin.readline().strip().split(' ')
    stack = Stack(100)
    
    for i in expr:
        if i == '*' or i == '+' or i == '-':
            n1 = stack.pop()
            n2 = stack.pop()
            ans = eval(n2 + i + n1)
            stack.push(str(ans))
        else:
            stack.push(i)

    print(stack.pop())
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    expr = sys.stdin.readline().strip().split(' ')
    stack = []
    
    for i in expr:
        if i == '*' or i == '+' or i == '-':
            n1 = stack.pop()
            n2 = stack.pop()
            ans = eval(n2 + i + n1)
            stack.append(str(ans))
        else:
            stack.append(i)

    print(stack.pop())
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ri = raw_input().split()
stack = []
for i in xrange(len(ri)):
  if ri[i] == "+":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)+int(b)))
  elif ri[i] == "-":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)-int(b)))
  elif ri[i] == "*":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)*int(b)))
  else:
    stack.append(ri[i])
print stack.pop()

Submission status: Accepted

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


input_list = input().split()
stack = list()
for i in input_list:
    if i.isdigit():
        stack.append(int(i))
    else:
        b = stack.pop()
        a = stack.pop()
        if i == '+':
            stack.append(a + b)
        elif i == '-':
            stack.append(a - b)
        elif i == '*':
            stack.append(a * b)
print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

stack = []
_l = input().split(' ')

for c in _l:
    if re.match(r"(\+|\-|\/|\*)", c):
        f = stack.pop()
        z = stack.pop()
        stack.append(eval("{}{}{}".format(z, c, f)))
    else:
        stack += [c]

print(stack[0])

Submission status: Accepted

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

array = []

for word in arguments:
    if word == '-':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s2-s1)
    elif word == '*':
        s1 =array.pop()
        s2 = array.pop()
        array.append(s1*s2)
    elif word == '+':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s1+s2)
    else:
        array.append(int(word))


print(array.pop())

Submission status: Accepted

Solution code:
#coding:UTF-8
def Stack(A):
    p=[]
    symbol=["+","-","*"]
    for i in range(len(A)):
        if A[i] in symbol:
            if A[i]=="+":
                p.append(p.pop()+p.pop())
            elif A[i]=="-":
                p.append(-p.pop()+p.pop())
            else:
                p.append(p.pop()*p.pop())
        else:
            p.append(int(A[i]))
    
    print(p[0])
  
if __name__=="__main__":
    a=input()
    A=a.split(" ")
    Stack(A)

Submission status: Accepted

Solution code:
command = raw_input().split(" ")
stack = []

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

print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input().split()
A = []
for i in x:
    try:
        A.append(int(i))
    except:
        b = A.pop()
        a = A.pop()
        if i == '+':
            A.append(a + b)
        if i == '-':
            A.append(a - b)
        if i == '*':
            A.append(a * b)
print(A.pop())

Submission status: Accepted

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


class Solution:
    @staticmethod
    def stack_polish_calc():
        # write your code here
        # array_length = int(input())
        calc_func = ('+', '-', '*')
        array = [str(x) for x in input().split()]
        # print(array)
        result = []
        for i in range(len(array)):
            if array[i] not in calc_func:
                result.append(str(array[i]))
            else:
                calc = array[i]
                arg_2 = result.pop()
                arg_1 = result.pop()
                result.append(str(eval(''.join((str(arg_1), calc, str(arg_2))))))

        print(*result)


if __name__ == '__main__':
    solution = Solution()
    solution.stack_polish_calc()

Submission status: Accepted

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


class Solution:
    @staticmethod
    def stack_polish_calc():
        # write your code here
        # array_length = int(input())
        calc_func = ('+', '-', '*')
        array = [str(x) for x in input().split()]
        # print(array)
        result = []
        for i in range(len(array)):
            if array[i] not in calc_func:
                result.append(str(array[i]))
            else:
                calc = array[i]
                arg_2 = result.pop()
                arg_1 = result.pop()
                result.append(str(eval(str(arg_1) + calc + str(arg_2))))

        print(*result)


if __name__ == '__main__':
    solution = Solution()
    solution.stack_polish_calc()

Submission status: Accepted

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

def calc(n,m,ope):
	n = int(n)
	m = int(m)
	rslt = 0
	if ope == "+":
		rslt = n + m
	elif ope == "-":
		rslt = n - m
	elif ope == "*":
		rslt = n * m
	else:
		try:
			raise ValueError("invalid operator!")
		except ValueError as e:
			print(e)
	return rslt
		
def main():
	formula = raw_input().split()
	stack = []
	for f in formula:
		if f == '+' or f == '-' or f == '*':
			pop1 = stack.pop()
			pop2 = stack.pop()
			rslt = calc(pop2, pop1,f)
			stack.append(rslt)
		else:
			stack.append(f)
		
	print stack.pop()




#def test():

if __name__ == '__main__':
	main()
	#test()

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
#????????????
#????????????python???????????????????????????????????????push???pop?????????
#??????????????????????????°????????§??????????§£???????????\??£???

def rpn(formula):
    stack = Stack()
    
    for d in formula:
        if d == "+":
            stack.push(stack.pop() + stack.pop())
        elif d == "-":
            stack.push(-stack.pop() + stack.pop())
        elif d == "*":
            stack.push(stack.pop() * stack.pop())
        else:
            stack.push(int(d))
            
    return stack.pop()

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

    def push(self, d):
        #print(self.data)
        self.data.append(d)
        
    def pop(self):
        #print(self.data)
        r = self.data[-1]
        self.data = self.data[:-1]
        return r
    
def main():
    formula = input().split()
    print(rpn(formula))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def solve(tokens):
    stack = []

    for token in tokens:
        if token == "+":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 + t2)
        elif token == "-":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t2 - t1)
        elif token == "*":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 * t2)
        else:
            stack.append(int(token))

    return stack.pop()


def main():
    print solve(raw_input().split())


if __name__ == "__main__":
    main()