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 reverse_polish_notation(A):
	ops = {'+': lambda a, b: b + a,
	       '-': lambda a, b: b - a,
	       '*': lambda a, b: b * a}

	stack = []

	for i in A:
		if i in ops:
			stack.append(ops[i](stack.pop(), stack.pop()))
		else:
			stack.append(int(i))

	return stack[0]

if __name__ == '__main__':
	A = list(input().split())
	print(reverse_polish_notation(A))

Submission status: Accepted

Solution code:
box = []
elem = input().split()
for i in elem:
    if i == '+' or i == '-' or i =='*':
        v = '{0} {1} {2}'.format(box[-2],i,box[-1])
        box.pop()
        box.pop()
        box.append(eval(v))
    else:
        box.append(i)
print (box[0])

Submission status: Accepted

Solution code:
#ALDS1_3-A Elementary data structures - Stack
A=input().split()
while(len(A)>1):
    for i in range(len(A)):
        if(A[i]=="+"):
            A[i]=int(A[i-2])+int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="-"):
            A[i]=int(A[i-2])-int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="*"):
            A[i]=int(A[i-2])*int(A[i-1])
            A=A[:i-2]+A[i:]
            break
print(A[0])

Submission status: Accepted

Solution code:
A=input().split()
B=[]
for i in A:
    if i.isdigit():
        B.append(int(i))
    else:
        if i=="+":
            B[-1]=B[-2]+B[-1]
            del B[-2]
        elif i=="-":
            B[-1]=B[-2]-B[-1]
            del B[-2]
        elif i=="*":
            B[-1]=B[-2]*B[-1]
            del B[-2]
print(B[0])

Submission status: Accepted

Solution code:
A=input().split()
B=[]
for i in A:
 if i.isdigit():
  B.append(int(i))
 else:
  if i=="+":
   B[-1]=B[-2]+B[-1]
   del B[-2]
  elif i=="-":
   B[-1]=B[-2]-B[-1]
   del B[-2]
  elif i=="*":
   B[-1]=B[-2]*B[-1]
   del B[-2]
print(B[0])

Submission status: Accepted

Solution code:
top = 0
def push(x):
    global top
    L.append(x)
    top += 1
def pop():
    global top
    x = L.pop(top)
    top -= 1
    return x

L = [0]
S = input().split()
for i in S:
    if i == "+":
        a = pop()
        b = pop()
        push(a + b)
    elif i == "-":
        a = pop()
        b = pop()
        push(b - a)
    elif i == "*":
        a = pop()
        b = pop()
        push(a * b)
    else:
        push(int(i))

print(str(pop()))

Submission status: Accepted

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

print(q[0])

Submission status: Accepted

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

if __name__ == '__main__':

    a = input().split(' ')
    b = []
    for i in a:
        if i == '+':
            tmp = b.pop(-1) + b.pop(-1)
            b.append(tmp)
        elif i == '-':
            p = b.pop(-1)
            tmp = b.pop(-1) - p
            b.append(tmp)
        elif i == '*':
            tmp = b.pop(-1) * b.pop(-1)
            b.append(tmp)
        else:
            b.append( int(i) )
    print(b[0])

Submission status: Accepted

Solution code:
# coding=utf-8
input = input().split()
stack = []

for i in input:
    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:
calcs = ["+", "-", "*", "/"]

#a="1 2 + 3 4 - *"
#a="1 2 +"
#lst = a.split()
lst = raw_input().split()

st=[]

def calc(e):

    tot=0
    tmp=0
    first=True

    b = st.pop()
    a = st.pop()

    if e   == "+":
        tot = a + b
    elif e == "-":
         tot = a- b
    elif e == "*":
         tot = a * b
    elif e == "/":
         tot = a / b

    st.append(tot)

for x in lst:
    if x in calcs:
       calc(x)
    else:
       st.append(int(x))

print st.pop()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def push(x, top, S):
      S.append(x)
      top = top + 1

def pop(top):
      del S[top-1]
      top = top - 1

if __name__ == "__main__":
      stdin = input()
      stdin = stdin.split()
      n = len(stdin)
      S = []
      top = len(S)
      for i in range(0, n):
            if stdin[i] == '+':
                  #print("+++++ top value is {}".format(top))
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a + b
            elif stdin[i] == '-':
                  #print("----- top value is {}".format(top))
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a - b
            elif stdin[i] == '*':
                  #print(print("***** top value is {}".format(top)))
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a * b
            else:
                  push(int(stdin[i]), top, S)
                  #print("when push {} top value is {}".format(int(stdin[i]),top))
      print(S[top])

Submission status: Accepted

Solution code:
def push(x, top, S):
      S.append(x)
      top = top + 1

def pop(top):
      del S[top-1]
      top = top - 1

if __name__ == "__main__":
      stdin = input()
      stdin = stdin.split()
      n = len(stdin)
      S = []
      top = len(S)
      for i in range(0, n):
            if stdin[i] == '+':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a + b
            elif stdin[i] == '-':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a - b
            elif stdin[i] == '*':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a * b
            else:
                  push(int(stdin[i]), top, S)
      print(S[top])

Submission status: Accepted

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

s = []
tmp = 0

for x in exp:
	if x == '+':
		tmp = int(s.pop()) + int(s.pop())
		s.append(tmp)
	elif x == '-':
		tmp = -1 * (int(s.pop()) - int(s.pop()))
		s.append(tmp)
	elif x == '*':
		tmp = int(s.pop()) * int(s.pop())
		s.append(tmp)
	else:
		s.append(int(x))

print(tmp)

Submission status: Accepted

Solution code:
import operator
def poland(A):
    l = []
    ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul }
    for i in range(len(A)):
        item = A.pop(0)
        if item in ops:
            l.append(ops[item](l.pop(-2),l.pop()))
        else:
            l.append(int(item))
    return l.pop()
    

if __name__ == '__main__':
    A = input().split()
    print (poland(A[:]))

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, stack = None):
        if type(stack) is type([]):
            self.stack = stack
            self.top = len(stack)
        else:
            self.stack = []
            self.top = 0
            
    def isEmpty(self):
        return self.top == 0
    
    def isFull(self):
        return self.top >= MAX - 1
            
    def push(self, e):
        if len(self.stack) != (self.top):
            self.stack[self.top] = e
        else:
            self.stack.append(e)
        self.top += 1
           
    def pop(self):
        self.top -= 1
        return self.stack[self.top]

S = input().split(" ")

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


stack = Stack()
for s in S:
    if s in operators:
        a = stack.pop()
        b = stack.pop()
#         print("%d %s %d"%(a, s, b))
        result = eval("%d %s %d"%(b, s, a))
        stack.push(result)
    else:
        stack.push(int(s))
print (stack.pop())

Submission status: Accepted

Solution code:
import sys

stack = []

array = sys.stdin.readline().strip().split(" ")

for op in array:
    if op.isdigit():
        stack.append(int(op))
    else:
        tmp1 = stack.pop()
        tmp2 = stack.pop()
        if op == "+":
            stack.append(tmp1 + tmp2)
        elif op == "-":
            stack.append(tmp2 - tmp1)
        elif op == "*":
            stack.append(tmp1 * tmp2)
        elif op == "/":
            stack.append(float(tmp2) / tmp1)
res = stack.pop()
print str(int(res))

Submission status: Accepted

Solution code:
def push(S, top, x):
      S.append(x)
      top = top + 1

def pop(S, top):
      t = int(S[top-1])
      del S[top-1]
      top = top -1
      return t

if __name__ == "__main__":
      top = 0
      inpt = (input()).split()
      n = len(inpt)
      S = []
      for i in range(0,n):
            if inpt[i] == "+":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a + b
                  push(S, top, c)
            elif inpt[i] == "-":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a - b
                  push(S, top, c)
            elif inpt[i] == "*":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a * b
                  push(S, top, c)
            else :
                  push(S, top, int(inpt[i]))
      print(S[top-1])

Submission status: Accepted

Solution code:
n = input().split()
array = []
for s in n:
    if s == "+" or s == "-" or s == "*":
        b = array.pop()
        a = array.pop()
        if   s == "+":
            array.append(a + b)
        elif s == "-":
            array.append(a - b)
        else:
            array.append(a * b)
    else:
        array.append(int(s))
print(array[0])

Submission status: Accepted

Solution code:
rp = [ele for ele in input().split()]
op = ['+','-','*']
stack = []
for ele in rp:
	if ele not in op:
		# ele is number
		stack.append(eval(ele))
	else:
		# ele is operator
		num_2 = stack.pop()
		num_1 = stack.pop()
		if ele == '+':
			stack.append(num_1 + num_2)
		elif ele == '-':
			stack.append(num_1 - num_2)
		else:
			# ele == '*'
			stack.append(num_1 * num_2)
print(stack[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????????????
???????????????????¨???????????????????????????????????????????????¨???°????????°??????????????°??????????¨???°???????¨??????§??????
????????°????????¬?????????????¨??????§?¨???°???????????°??? (1+2)*(5+4) ??????
???????????????????¨??????§??? 1 2 + 5 4 + * ??¨?¨???°???????????????
???????????????????¨??????§?????????????¨??????§????????¨????????¬??§???????????§???????????¨????????????????????????????????????

???????????????????¨??????§?????????????????°???????¨????????????????????????????????????????

"""

# ?????????
INP = list(input().strip().split())
TMP = []
res = 0
for i in INP:
    if i == "+":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a + b)
#        print("{} - {} = {}".format(a,b,a+b))
    elif i == "-":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a - b)
#        print("{} - {} = {}".format(a,b,a-b))
    elif i == "*":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a * b)
#        print("{} * {} = {}".format(a,b,a*b))
    else:
        TMP.append(int(i))

print(TMP.pop())

Submission status: Accepted

Solution code:
p = lambda x,y:x+y
m = lambda x,y:x-y
t = lambda x,y:x*y
ope = {'+':p, '-':m, '*':t}

data = [int(s) if s.isdigit() else s for s in input().split()]
while len(data) > 1:
	isope = [isinstance(d,str) for d in data]
	ope_idx = isope.index(True)
	xy = data[ope_idx-2:ope_idx]
	ans = ope[data[ope_idx]](*xy)
	data = data[:ope_idx-2] + [ans] + data[ope_idx+1:]

print(data[0])

Submission status: Accepted

Solution code:

def add(Stack):
    tmp = Stack[-1] + Stack[-2]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

def subtract(Stack):
    tmp = Stack[-2] - Stack[-1]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

def multiple(Stack):
    tmp = Stack[-1] * Stack[-2]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

A = input().split()
Stack = []

for i in range(len(A)):
    if A[i] == '+':
        add(Stack)
    elif A[i] == '-':
        subtract(Stack)
    elif A[i] == '*':
        multiple(Stack)
    else:
        Stack.append(int(A[i]))

print(str(Stack[0]))

Submission status: Accepted

Solution code:
def r_poland(s):
    stack=[]
    
    for d in s:
        if d.isdigit():
            stack.append(int(d))
        elif d=="+":
            stack[-1]+=stack.pop(-2)
        elif d=="-":
            stack[-1]=stack.pop(-2)-stack[-1]
        elif d=="*":
            stack[-1]*=stack.pop(-2)

    return stack
   
s=list(input().split())

print(*r_poland(s))

Submission status: Accepted

Solution code:

data = input().split()
n = len(data)

stack=[]

for i in data:
    if i == "+":
        x1 = int(stack.pop())
        x2 = int(stack.pop())
        stack.append(x1+x2)
    elif i == "-":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1-x2)
    elif i == "*":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1*x2)
    elif i == "/":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1-x2)
    else:
        stack.append(int(i))
print(stack[0])

Submission status: Accepted

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

Submission status: Accepted

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


op = ['+', '*', '-']
stack = []

for j in i:
    if j in op:
        r = stack.pop()
        l = stack.pop()
        stack.append(str(eval(l + j + r)))
    else:
        stack.append(j)
print (stack[0])

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def pop(self):
        return self.el.pop()

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

        
a = raw_input().split()
#print a
st = Stack()

for index in range(len(a)):
    #print a[index]
    if a[index] in ['+', '-', '*']:
        num1 = st.pop()
        num2 = st.pop()
        if a[index] == '+':
            st.add(int(num1) + int(num2))
        elif a[index] == '-':
            st.add(int(num2) - int(num1))
        else:
            st.add(int(num1) * int(num2))
    else:
        st.add(a[index])
    #print st.el

ans = st.pop()
print ans

Submission status: Accepted

Solution code:
from collections import deque

S = input().split()
dq = deque()

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

print(dq[0])

Submission status: Accepted

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

numbers = list("1234567890")
querry = [n for n in input().split()]

stack = []

for q in querry:
    if q == "+":
        stack.append(stack.pop() + stack.pop())
    elif q == "-":
        stack.append(-stack.pop() + stack.pop())
    elif q == "*":
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(q))

print(stack.pop())

Submission status: Accepted

Solution code:
# your code goes here
#polland
def nu(x):
    if x=="+" or x=="-" or x=="*":
        return 0
    else:
        return 1
def c(a,b,l):
    if l=="+":
        d=a+b
    elif l=="-":
        d=a-b
    else:
        d=a*b
    return d
F=[i for i in input().split()]
i=0
S=[]
while i<len(F):
    if nu(F[i])==0:
        S[-2]=c(S[-2],S[-1],F[i])
        S.pop(-1)
    else:
        S.append(int(F[i]))
    i+=1
print(S[0])

Submission status: Accepted

Solution code:
# Aizu Problem ALDS_1_3_A: Stack
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


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

print(stack[0])

Submission status: Accepted

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

    def pop(self):
        if self.n == 0:
            raise Exception("stack underflow")
        else:
            v = self.values[-1]
            del self.values[-1]
            self.n -= 1
            return v

    def push(self,x):
        self.values.append(x)
        self.n += 1


operators = set(['+', '-', '*'])
stack = Stack()

for op in raw_input().split(' '):
    if op in operators:
        b = stack.pop()
        a = stack.pop()
        if op == '+':
            stack.push(a+b)
        elif op == '-':
            stack.push(a-b)
        elif op == '*':
            stack.push(a*b)
        else:
            raise Exception("Unkown operator")
    else:
        stack.push(int(op))

print stack.pop()

Submission status: Accepted

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

answer=[]
for i in range(len(x)):
    if x[i].isdigit():
        answer.append(int(x[i]))
    elif x[i]=="+":
        t=answer.pop()+answer.pop()
        answer.append(t)
    elif x[i]=="-":
        t=-1*(answer.pop()-answer.pop())
        answer.append(t)
    elif x[i]=="*":
        t=answer.pop()*answer.pop()
        answer.append(t)

print(*answer)

Submission status: Accepted

Solution code:
S = []
A = raw_input().split()

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

print S[0]

Submission status: Accepted

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

for i in A:
    if i.isdigit():
        N.append(i)
    elif str(i) == '+':
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) + int(t1)
        N.append(t3)
    elif str(i) == '*':
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) * int(t1)
        N.append(t3)
    else:
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) - int(t1)
        N.append(t3)

print(N.pop())

Submission status: Accepted

Solution code:
data = input().split()
operator = ["+", "*", "-"]
stack = []
for x in data:
    if x in operator:
        a = stack.pop()
        b = stack.pop()
        stack.append(str(eval(b + x + a)))
    else:
        stack.append(x)
print(stack[0])

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    x = [(int)(x) if x.isdigit() else x for x in input().split()]
    
    y = deque()

    for tmp in x:
        if tmp == '+':
            a = y.pop()
            b = y.pop()
            y.append(a+b)
        elif tmp == '-':
            a = y.pop()
            b = y.pop()
            y.append(b-a)
        elif tmp == '*':
            a = y.pop()
            b = y.pop()
            y.append(a*b)
        elif tmp == '/':
            a = y.pop()
            b = y.pop()
            y.append(b//a)
        else:
            y.append(tmp)

    print(y.pop())

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    x = [(int)(x) if x.isdigit() else x for x in input().split()]
    
    y = deque()

    for tmp in x:
        if tmp == '+':
            a = y.pop()
            b = y.pop()
            y.append(a+b)
        elif tmp == '-':
            a = y.pop()
            b = y.pop()
            y.append(b-a)
        elif tmp == '*':
            a = y.pop()
            b = y.pop()
            y.append(a*b)
        else:
            y.append(tmp)

    print(y.pop())

Submission status: Accepted

Solution code:


s = input().split()

stack = []

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

print(stack[0])

Submission status: Accepted

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

stack = []
for inp in a:
    if inp == "+":
        x = stack.pop()
        y = stack.pop()
        stack.append(x+y)
    elif inp == "-":
        x = stack.pop()
        y = stack.pop()
        stack.append(y-x)
    elif inp == "*":
        x = stack.pop()
        y = stack.pop()
        stack.append(x*y)
    else:
        stack.append(int(inp))

print(*stack)

Submission status: Accepted

Solution code:
fig = input()
symbol = fig.split(' ')
stack = []

for i in symbol:
    try:
        stack.append(int(i))
    except ValueError:
       if i == "+": stack.append(stack.pop()+stack.pop())
       elif i == "-": stack.append(-(stack.pop()-stack.pop()))
       elif i == "*": stack.append(stack.pop()*stack.pop())

print(stack[0])

Submission status: Accepted

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

Submission status: Accepted

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

stack = []

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

print(stack[0])

Submission status: Accepted

Solution code:
lst = raw_input().split()
lst2 = []
for v in lst:
    if v == "+":
        lst2[len(lst2)-2] += lst2.pop()
    elif v == "-":
        lst2[len(lst2)-2] -= lst2.pop()
    elif v == "*":
        lst2[len(lst2)-2] *= lst2.pop()
    elif v == "/":
        lst2[len(lst2)-2] /= lst2.pop()
    else:
        lst2.append(int(v))
print lst2[0]

Submission status: Accepted

Solution code:
def ALDS1_3A():
  stk, RPexp = [], list(input().split())
  for v in RPexp:
      if v in '+-*':
          n2, n1 = stk.pop(), stk.pop()
          stk.append(str(eval(n1+v+n2)))
      else:
          stk.append(v)
  print(stk.pop())

if __name__ == '__main__':
    ALDS1_3A()

Submission status: Accepted

Solution code:
A = list(map(str,input().split()))
Stack = []
for e in A:
    if e.isdigit():
        Stack.append(int(e))
    else:
        right = Stack.pop()
        left = Stack.pop()
        if e == "+":
            Stack.append(left+right)
        elif e == "-":
            Stack.append(left-right)
        elif e == "*":
            Stack.append(left*right)
        else:
            if right != 0:
                Stack.append(left//right)
            else:
                print("0?????????")
                exit()

print(Stack.pop())

Submission status: Accepted

Solution code:
class Stack(object):
    def __init__(self, _max):
        if type(_max) == int:
            self._array = [None for i in range(0, _max)]
            self._next = 0

    def push(self, value):
        if self.isFull():
            raise IndexError
        self._array[self._next] = value
        self._next += 1

    def pop(self):
        if self.isEmpty():
            raise IndexError
        self._next -= 1
        value = self._array[self._next]
        self._array[self._next] = None
        return value

    def isEmpty(self):
        return self._next <= 0

    def isFull(self):
        return self._next >= len(self._array)


def calculator(exp):
    stack = Stack(100)
    ope = ["+", "-", "*"]
    for item in exp:
        if item in ope:
            val1 = stack.pop()
            val2 = stack.pop()
            if item == "+":
                stack.push(val2 + val1)
            elif item == "-":
                stack.push(val2 - val1)
            elif item == "*":
                stack.push(val2 * val1)
            else:
                raise ValueError
        else:
            stack.push(int(item))
    return stack.pop()


if __name__ == "__main__":
    exp = input().split()
    print(calculator(exp))

Submission status: Accepted

Solution code:
expr = input().split()
my_stack = []
def push(stack, item):
    return stack.append(item)

def pop(stack):
    return stack[:-1], stack[-1]

for item in expr:
    if item.isdigit():
        push(my_stack, int(item))
    elif item == '+':
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, a + b)
    elif item == '-':
        # not a - b
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, b - a)
    elif item == '*':
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, a * b)

print(my_stack[0])

Submission status: Accepted

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

# ??????????????????????????????????£?
# n : ????????????????????????
# S : ????????????
n = 1000
S = [0 for i in range(n)]

def isEmpty():
    global top
    if (top == 0):
        return True
    else:
        return False

def isFull():
    global top, n
    return top > n-1

def push(S, x):
    global top
    if isFull():
        print('error: overflow')
        return False
    top += 1
    S[top] = x

def pop(S):
    global top
    if isEmpty():
        print('error: underflow')
        return False
    top -= 1
    return S[top+1]

top = 0

for e in data:


    if e.isdigit():
        push(S, e)
    else:
        a = int(pop(S))
        b = int(pop(S))

        if e == '+':
            push(S, b + a)
        elif e == '-':
            push(S, b - a)
        elif e == '*':
            push(S, b * a)
        else:
            print('error: operand')


print(S[top])

Submission status: Accepted

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

print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = raw_input().split()
#figure = [chr(i) for i in range(ord('0'), ord('9')+1)]

stack = []

for i in range(len(data)):
	if data[i] == "+":
		stack[-2] = stack[-2] + stack[-1]
		del stack[-1]
		#print stack
	elif data[i] == "-":
		stack[-2] = stack[-2] - stack[-1]
		del stack[-1]
		#print stack
	elif data[i] == "*":
		stack[-2] = stack[-2] * stack[-1]
		del stack[-1]
		#print stack
	else:
		stack.append(int(data[i]))
		#print stack

print stack[0]

Submission status: Accepted

Solution code:
s=input().split()
a=[]
for i in s:
    if i in ["+","-","*"]:
        a1=str(a.pop())
        a2=str(a.pop())
        t = eval(a2+i+a1)
        a.append(t)
    else:
        a.append(int(i))
print(a.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main() :
    lst = input().split()
    stack = []
    for i in lst :
        if i == '+' :
            x = stack.pop()
            y = stack.pop()
            stack.append(x + y)

        elif i == '-':
            x = stack.pop()
            y = stack.pop()
            stack.append(y - x)

        elif i == '*' :
            x = stack.pop()
            y = stack.pop()
            stack.append(x * y)

        else :
            stack.append(int(i))

    print(stack.pop())

if __name__ == '__main__' :
    main()

Submission status: Accepted

Solution code:
def main() :
    lst = input().split()
    stack = []
    for i in lst :
        if i == "+" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x + y)

        elif i == "-" :
            x = stack.pop()
            y = stack.pop()
            stack.append(y - x)

        elif i == "*" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x * y)

        else :
            stack.append(int(i))

    print(stack.pop())


if __name__ == "__main__" :
    main()