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 10 6  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 × 10 9 ≤ values in the stack ≤ 10 9  Sample Input 1 1 2 + Sample Output 1 3 Sample Input 2 1 2 + 3 4 - * Sample Output 2 -3 Notes Template in C

Solution (Python):
import sys

for line in sys.stdin:
  items = line.strip().split()

stack = []

for item in items:
  if item == '+' or item == '-' or item == '*':
    x = stack.pop()
    y = stack.pop()
    exp = "%s %s %s" % (y, item, x)
    stack.append(eval(exp))
  else:
    stack.append(int(item))

print stack.pop()

Solution (Python):
A = raw_input().split()
B = []
def add(x, y):
    return x + y
def sub(x, y):
    return x - y
def mul(x, y):
    return x * y
operation = {'+':add, '-':sub, '*':mul}
for item in A:
    if item.isdigit():
        B.append(int(item))
    else:
        num2 = B.pop() 
        num1 = B.pop()
        ans = operation[item](num1, num2)
        B.append(ans)
print ans

Solution (Python):
A = raw_input().split()
B = []

def add(x,y):
    return x + y
def sub(x,y):
    return x - y
def mul(x,y):
    return x * y
operation = {'+':add, '-':sub, '*':mul}

for item in A:
    if item.isdigit():
        B.append(int(item))
    else:
        num2 = B.pop()
        num1 = B.pop()
        ans = operation[item](num1, num2)
        B.append(ans)
print ans

Solution (Python):
import sys

def isEmpty(S):
  if len(S) == 0:
    return True
  
def isFull(S):
  if len(S) >= 101:
    return True

def push(x):
  if isFull(S):
    print 'Error'
  S.append(x)
  
def pop(top):
  if isEmpty(S):
    print 'error'
  k = S[top]
  S.pop()
  return k

S = []
top = -1

x = sys.stdin.readline().strip()
x_list = x.split(" ")

for i in range(0, len(x_list)):
  if x_list[i] == '*':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(a * b)
    top += 1
    
  elif x_list[i] == '+':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(a + b)
    top += 1
    
  elif x_list[i] == '-':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(b - a)
    top += 1
    
  else:
    push(x_list[i])
    top += 1
    
a = int(pop(top))
print a

Solution (Python):
import sys


Stack = []
MAX = 1000

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

def pop():
    
    
    
    Stack.pop(-1)

def cul(exp):
    for v in exp:
        if v == "+":
            x = reduce(lambda a,b:int(a)+int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        elif v == "-":
            x = reduce(lambda a,b:int(a)-int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        elif v == "*":
            x = reduce(lambda a,b:int(a)*int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        else:
            push(v)

    return Stack[0]

if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans

Solution (Python):
S = raw_input().split(" ")
Stack = list()

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

def pop():
    return Stack.pop(-1)

a = 0
b = 0
for i in range(len(S)):
    if S[i] == "+":
        a = pop()
        b = pop()
        push(b + a)
    elif S[i] == "-":
        a = pop()
        b = pop()
        push(b - a)
    elif S[i] == "*":
        a = pop()
        b = pop()
        push(b * a)
    elif S[i] == "/":
        a = pop()
        b = pop()
        push(b / a)
    else:
        push(int(S[i]))

print Stack.pop(-1)

Solution (Python):
import sys


Stack = []

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

def pop():
    Stack.pop(-1)


def cul(exp):
    for val in exp:
        if val in ["+", "-", "*"]:
            a = int(Stack[-2])
            b = int(Stack[-1])
            if val == "+":
                x = a + b
            elif val == "-":
                x = a - b
            elif val == "*":
                x = a * b
            for i in range(2):
                pop()
            push(x)
        else:
            push(val)

    return Stack[0]


if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans

Solution (Python):
class Stack(list):
    def __init__(self):
        self.length = 0
    def __len__(self):
        return self.length

    def push(self,x):
        self.insert(len(self),x)
        self.length += 1
    def pop(self):
        try:
            if(len(self)==0):
                raise NameError("stack is empty")
            tmp = self[len(self)-1]
            self.length -= 1
            return tmp
        except:
            print("stack is empty!!!!")
            return '

data = Stack()
s = input()
x = s.split()

for i in x:
    if i == '+':
        a = data.pop()
        b = data.pop()
        data.push(b+a)

    elif i == '-':
        a = data.pop()
        b = data.pop()
        data.push(b-a)


    elif i == '*':
        a = data.pop()
        b = data.pop()
        data.push(b*a)
  
    else:
        data.push(int(i))
print(data.pop())

Solution (Python):
class Stack():
    def __init__(self):
        self.stack = [0 for _ in range(1000)]
        self.top = 0

    def push(self, n):
        self.top += 1
        self.stack[self.top] = n

    def pop(self):
        a = self.stack[self.top]
        del self.stack[self.top]
        self.top -= 1
        return a

    def lol(self):
        return self.stack[self.top]


def main():
    input_data = raw_input()
    data = input_data.strip().split(" ")
    st = Stack()
    for l in data:
        if l == "+":
            a = st.pop()
            b = st.pop()
            st.push(a + b)

        elif l == "-":
            a = st.pop()
            b = st.pop()
            st.push(b - a)

        elif l == "*":
            a = st.pop()
            b = st.pop()
            st.push(a * b)

        else:
            st.push(int(l))

    print st.lol()


if __name__ == '__main__':
    main()

Solution (Python):
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val

class Stack:
    member=Trio(None)
    def __init__(self,stri):
        if(isinstance(stri,str)):
            for i,e in enumerate(stri):
                if(i==0):
                    self.member.set_val(e)
                else:
                    self.push(e)

    
    def push(self,n):
        self.member.set_nex(Trio(n,self.member,None))
        self.member=self.member.get_nex()

    def pop(self):
        if(self.member==None):
            return None
        d=self.member.get_val()
        self.member=self.member.get_pre()
        return d

s=input()
stk = Stack(None)
stri=""
for i in s:
    if(i==" "):
        stk.push(stri)
        stri=""
    elif(i.isdigit()):
        stri="".join([stri,i])
    elif(i=="+" or i=="-" or i=="*"):
        b=stk.pop()
        b=int(b)
        a=int(stk.pop())
        if(i=="+"):
            stri=(str(a+b))
        elif(i=="-"):
            stri=(str(a-b))
        else:
            stri=(str(a*b))

print(stri)

Solution (Python):
class Stack():
    def __init__(self):
        self.stack = [0 for _ in range(200)]
        self.top = 0

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

    def isFull(self):
        return self.top >= len(self.stack) - 1

    def push(self, x):
        if self.isFull():
            print "error"
            return exit()
        self.top += 1
        self.stack[self.top] = x

    def pop(self):
        if self.isEmpty():
            print "error"
            return exit()
        a = self.stack[self.top]
        del self.stack[self.top]
        self.top -= 1
        return a

    def lol(self):
        return self.stack[self.top]

def main():
    st = Stack()
    data = raw_input().split()
    for i in data:
        if i == '+':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a + b)
        elif i == '-':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a - b)
        elif i == '*':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a * b)
        else:
            st.push(i)
    print st.lol()

if __name__ == '__main__':
    main()

Solution (Python):


formula = input().split()
stack = []
for char in formula:
    if char.isdigit():
        stack.append(char)
    else:
        ans = str(eval(stack.pop(len(stack)-2) + char + stack.pop()))
        stack.append(ans)
print(stack.pop())

Solution (Python):
class Stack:
    
    def __init__(self):
        self.top = 0
        self.Max = 100
        self.stack = [None]

    def isEmpty(self):
        return self.top == 0
    
    def isFull(self):
        return self.top >= self.Max

    def push(self, x):
        if self.isFull():
            print("Stack overflow!")
        else:
            self.top += 1
            self.stack.append(x)

    def pop(self):
        if self.isEmpty():
            print("Stack underflow!")
        else:
            self.top -= 1
            return self.stack.pop()

d_e = input().split()

accumlator = Stack()

for i in d_e:
    if i in "+-*":
        post_op = accumlator.pop()
        pre_op = accumlator.pop()
        ans = eval(pre_op + i + post_op)
        accumlator.push(str(ans))
    else:
        accumlator.push(i)

print(int(accumlator.pop()))

Solution (Python):



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


def calc(symbols):
    stack = []
    for s in symbols:
        if s in OPERATORS:
            a = stack.pop()
            b = stack.pop()
            if s == "+":
                stack.append(b + a)
            elif s == "-":
                stack.append(b - a)
            elif s == "*":
                stack.append(b * a)
        else:
            stack.append(int(s))
    return stack[-1]


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


if __name__ == "__main__":
    main()

Solution (Python):
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()

Solution (Python):


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()

Solution (Python):
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()

Solution (Python):
poland = input().split()
num = []
for p in poland:
    if p.isdigit():
        num.append(int(p))
    else:
        b = num.pop()
        a = num.pop()
        if p == '*':
            num.append(a * b)
        elif p == '/':
            num.append(a / b)
        elif p == '+':
            num.append(a + b)
        elif p == '-':
            num.append(a - b)
print(num.pop())

Solution (Python):
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])

Solution (Python):
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])

Solution (Python):
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())

Solution (Python):
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())

Solution (Python):
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))

Solution (Python):
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()

Solution (Python):
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())

Solution (Python):
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)

Solution (Python):
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]

Solution (Python):

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()

Solution (Python):
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])

Solution (Python):
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()

Solution (Python):
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()

pos = 0
n = make_node(s)

print "%d" % calc_node(n)

Solution (Python):
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])

Solution (Python):
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)))

Solution (Python):


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]

Solution (Python):
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])

Solution (Python):

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())

Solution (Python):
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]

Solution (Python):
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]

Solution (Python):
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]

Solution (Python):
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])

Solution (Python):
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])

Solution (Python):


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()
    
    for i in xrange(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print calculation(A)

Solution (Python):


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()
    
    for i in xrange(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print calculation(A)

Solution (Python):
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())

Solution (Python):
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()

Solution (Python):
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]

Solution (Python):
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])

Solution (Python):




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()

Solution (Python):
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()

Solution (Python):

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]

        
        elements = elements[:i-2] + [r] + elements[i+1:]
    else:
        break

print(elements[0])

Solution (Python):
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()

Solution (Python):


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)

Solution (Python):
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])

Solution (Python):

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]))

Solution (Python):

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]))

Solution (Python):

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]))

Solution (Python):

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]))

Solution (Python):




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()

Solution (Python):




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()

Solution (Python):
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())