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:
stack = input().split()
temp  =  []
num=0
for loop in stack:
    a = loop
    if a is "+":
        num = temp.pop() + temp.pop()
        temp.append(num)
    elif a is "-":
        b=temp.pop()
        c=temp.pop()
        num = c-b
        temp.append(num)
    elif a is "*":
        num = temp.pop() * temp.pop()
        temp.append(num)
    else:
        temp .append(int(a))

print(temp[0])

Submission status: Accepted

Solution code:
import re

data = input().split(' ')
stack = []
for w in data:
    if re.match(r'[0-9]', w):
        stack.append(w)
        # print(stack)
    else:
        r = stack.pop()
        l = stack.pop()
        stack.append(eval(str(l) + w + str(r)))
        # print(stack)

print(stack[0])

Submission status: Accepted

Solution code:
import sys

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
STACK = []


def main():
    inp = get_input()
    print(calc_stack(li=inp))


def calc_stack(li):
    if li[0] in OPECODE:
        ans = calc(left=STACK[-2], right=STACK[-1], ope=li[0])

        del li[0]
        if not li:
            return ans

        STACK.pop()
        STACK.pop()
        STACK.append(ans)

        return calc_stack(li=li)

    else:
        STACK.append(int(li[0]))
        del li[0]
        return calc_stack(li=li)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    operand_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            operand_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if operand_count < 2 or operand_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
BUF = []


def main():
    stack = get_input()
    ans = calc_stack(stack=stack)
    print(ans)


def calc_stack(stack):
    if stack[-1] in OPECODE:
        BUF.append(stack[-1])
        stack.pop()
        return calc_stack(stack=stack)
    else:
        right_num = int(stack[-1])
        stack.pop()
        if stack[-1] in OPECODE:
            BUF.append(right_num)
            BUF.append(stack[-1])
            stack.pop()
            return calc_stack(stack=stack)
        else:
            left_num = int(stack[-1])
            stack.pop()
            stack.append(calc(left_num, right_num, BUF[-1]))
            BUF.pop()
            stack.extend(reversed(BUF))
            BUF.clear()

        if len(stack) == 1:
            return stack[0]
        else:
            return calc_stack(stack=stack)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    OPECODE_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            OPECODE_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if OPECODE_count < 2 or OPECODE_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Submission status: Accepted

Solution code:
import sys

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
STACK = []


def main():
    inp = get_input()
    print(calc_stack(li=inp))


def calc_stack(li):
    for l in li:
        if l in OPECODE:
            STACK.append(calc(right=STACK.pop(), left=STACK.pop(), ope=l))
        else:
            STACK.append(int(l))

    return STACK[0]


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    operand_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            operand_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if operand_count < 2 or operand_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Submission status: Accepted

Solution code:

class Stack():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop()

# def isint(s):
#     try: 
#         int(s)
#         return True
#     except ValueError:
#         return False

ope = {"+", "-", "*"}

s = Stack()
exp = input().strip().split()

for e in exp:
    if e in ope:
        if e == '+':
            s.push(s.pop() + s.pop())
        elif e == '-':
            tmp = s.pop()
            s.push(s.pop() - tmp)
        else:
            s.push(s.pop() * s.pop())
    else:
        s.push(int(e))
print(s.pop())

Submission status: Accepted

Solution code:
input_str = input().split(' ')

stack = []

left_num, right_num = 0, 0
for tmp_str in input_str:
    if tmp_str == '+':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num + right_num)

    elif tmp_str == '-':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num - right_num)

    elif tmp_str == '*':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num * right_num)

    elif tmp_str == '/':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num / right_num)

    else:
        stack.append(int(tmp_str))

print(stack.pop())

Submission status: Accepted

Solution code:
notation = input().split()
stack = []
for s in notation:
    try:
        stack.append(int(s))
    except:
        n = 0
        if s == '+':
            n = stack[-2] + stack[-1]
        elif s == '-':
            n = stack[-2] - stack[-1]
        elif s == '*':
            n = stack[-2] * stack[-1]
        elif s == '/':
            n = stack[-2] / stack[-1]

        stack = stack[:-2] + [n]

assert(len(stack) == 1)
print(stack[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	l = input().split()
	count = 0

	for i in range(len(l)):
		i -= count
		if l[i] == '+':
			l[i - 2] = str(int(l[i - 2])  + int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		elif l[i] == '-':
			l[i - 2] = str(int(l[i - 2])  - int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		elif l[i] == '*':
			l[i - 2] = str(int(l[i - 2])  * int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		else:
			continue
	if len(l) > 1:
		print("Error")
	else:
		print(l[0])

Submission status: Accepted

Solution code:
x = input().split()
s = []
for i in x:
    try:
        i = int(i)
        s.append(i)
    except:
        s.append(eval('{b}{ope}{a}'.format(a=s.pop(), ope=i, b=s.pop())))
print(s[0])

Submission status: Accepted

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

if __name__ == '__main__':

    stack = []
    line = input().split(" ")
    for s in line:
        if s.isdigit():
            stack.append(s)
        else:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(str(eval(v1 + s + v2)))

    print(stack.pop())

Submission status: Accepted

Solution code:
from operator import *
li = []
for s in input().split():
    if s.isdigit():
        li.append(int(s))
    else:
        b = li.pop()
        a = li.pop()
        li.append({"+":add, "-":sub, "*":mul}[s](a, b))
print(li[-1])

Submission status: Accepted

Solution code:
s = []
e = input().split()

for c in e:
    if c in "+-*":
        a = s.pop()
        b = s.pop()
        s.append(str(eval(b + c + a)))
    else:
        s.append(c)

print(s[0])

Submission status: Accepted

Solution code:
s=[]
for i in input().split():
 n=len(s)-1
 if i=='+':s.append(s[n-1]+s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='-':s.append(s[n-1]-s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='*':s.append(s[n-1]*s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='/':s.append(s[n-1]/s[n]);s.pop(n-1);s.pop(n-1)
 else:s.append(int(i))
print(*s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

stack = []

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

print(stack[0])

Submission status: Accepted

Solution code:
eq=input().split(' ')

class Stack():
	def __init__(self):
		self.S=[]
		self.top=-1
		
	def initialize(self):
		self.top=-1
	
	def isEmpty(self):
		if self.top==-1:
			return('Empty')
		else:
			return('Not Empty')
	
	def push(self,x):
		self.S.append(x)
		self.top+=1
	
	def pop(self):
		a=self.S[self.top]
		del self.S[self.top]
		self.top-=1
		return(a)
		
	
	
	
c=Stack()
for i in range(len(eq)):
	if eq[i].isdigit():
		c.push(eq[i])
	else:
		a=c.pop()
		b=c.pop()
		if eq[i]=='+':
			c.push(int(b)+int(a))
		elif eq[i]=='-':
			c.push(int(b)-int(a))
		else:
			c.push(int(b)*int(a))
			
print(c.pop())

Submission status: Accepted

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

def reverse_polish_notation(data):
    operands = [];
    for n in data:
        if n not in "*+-":
            operands.append(int(n));
        else:
            operand_second = operands.pop();
            operand_first = operands.pop();
            operands.append(calculate(n, operand_first, operand_second));
    return operands[0];

def calculate(operator, a, b):
    if operator == "*":
        return a * b;
    elif operator == "-":
        return a - b;
    elif operator == "+":
        return a + b;

print(reverse_polish_notation(data));

Submission status: Accepted

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

for i in range(len(s)):
    if s[i]=="+":
        b=k.pop()
        a=k.pop()
        k.append(int(a)+int(b))
    elif s[i]=="-":
        b=k.pop()
        a=k.pop()
        k.append(int(a)-int(b))
    elif s[i]=="*":
        b=k.pop()
        a=k.pop()
        k.append(int(a)*int(b))

    else:
        k.append(s[i])

print(k[0])

Submission status: Accepted

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

stack = []
for i in s:
    if i.isdigit():
        stack.append(int(i))
    else:
        if i == "+":
            f = lambda x, y: x + y
        elif i == "-":
            f = lambda x, y: x - y
        elif i == "*":
            f = lambda x, y: x * y

        y = stack.pop()
        x = stack.pop()
        stack.append(f(x, y))

print(stack[0])

Submission status: Accepted

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

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

print(stack.pop())

Submission status: Accepted

Solution code:
import sys
str = ""
for line in sys.stdin:
	str = line

numbers = str.split()

answer = 0
stackList = []

for number in numbers :

    if number == '+' :
        answer = int(stackList.pop()) + int(stackList.pop())
        stackList.append(answer)
    elif number == '-' :
        x = int(stackList.pop())
        y = int(stackList.pop())
        answer = y - x
        stackList.append(answer)
    elif number == '*' :
        answer = int(stackList.pop()) * int(stackList.pop())
        stackList.append(answer)
    else :
        stackList.append(number)

print(answer)

Submission status: Accepted

Solution code:
import sys
str = ""
for line in sys.stdin:
	str = line

numbers = str.split()

answer = 0
stackList = []

for number in numbers :

    if number == '+' :
        answer = int(stackList.pop()) + int(stackList.pop())
        stackList.append(answer)
    elif number == '-' :
        x = int(stackList.pop())
        y = int(stackList.pop())
        answer = y - x
        stackList.append(answer)
    elif number == '*' :
        answer = int(stackList.pop()) * int(stackList.pop())
        stackList.append(answer)
    else :
        stackList.append(number)

print(answer)

Submission status: Accepted

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

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

stack = []
for item in list:
  if item in OPERATOR:
    b = stack.pop()
    a = stack.pop()
    stack.append(OPERATOR[item](a, b))
  else:
    stack.append(int(item))

print(stack.pop())

Submission status: Accepted

Solution code:
# coding: UTF-8
from collections import deque
operators = {'+','*','-'}

def operate(L,R,C):
  if C == '+':
    return L + R
  elif C == '*':
    return L * R
  else: #<=>if C == '-'
    return L - R

raw = input().split()
stack = deque()
for C in raw:
  if C in operators:
    R = stack.pop()
    L = stack.pop()
    stack.append(operate(L,R,C))
  else:
    stack.append(int(C))
print(stack.pop())

Submission status: Accepted

Solution code:
hoge = list()
for elem in (elem for elem in input().split()):
    if elem == '+':
        elem = int(hoge.pop()) + int(hoge.pop())
    elif elem == '*':
        elem = int(hoge.pop()) * int(hoge.pop())
    elif elem == '-':
        elem = -1*int(hoge.pop()) + int(hoge.pop())
    hoge.append(elem)
print (elem)

Submission status: Accepted

Solution code:
a = input().split()
b = []
for i in a:
    if i.isdigit():
        b.append(i)
    else:
        c = b.pop()
        d = b.pop()
        ans = eval(str(d)+i+str(c))
        b.append(ans)
print(b[0])

Submission status: Accepted

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

import sys

def calc(operator, stack):
    val_b = stack.pop()
    val_a = stack.pop()

    if operator == '+':
        stack.append(val_a + val_b)
    elif operator == '-':
        stack.append(val_a - val_b)
    elif operator == '*':
        stack.append(val_a * val_b)
    else:
        raise ValueError

stack = list()
inline = sys.stdin.readline().split()  # List of string
for val in inline:
    if val in '+-*':
        calc(val, stack)
    else:
        stack.append(int(val))

print(stack.pop())

Submission status: Accepted

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

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

print(b[0])

Submission status: Accepted

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*?)\s(\-?\d+\.?\d*?)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Submission status: Accepted

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Submission status: Accepted

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

if __name__=='__main__':
    print(revPolish(input()))

Submission status: Accepted

Solution code:
import re
pat = re.compile(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)')

def revPolish(f):
    global pat
    f = pat.sub(lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),f)
    if f[-1] in '+-*/':
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Submission status: Accepted

Solution code:
L = list(map(str, input().split(' ')))
que = []
while len(L) != 0:
    if L[0] not in ('+', '-', '*'):
        que.append(int(L.pop(0)))
    else:
        if L[0] == '+':
            a = que[-2] + que[-1]
        elif L[0] == '-':
            a = que[-2] - que[-1]
        elif L[0] == '*':
            a = que[-2] * que[-1]
        L.pop(0)
        que.pop(-1)
        que.pop(-1)
        que.append(a)
print(que[0])

Submission status: Accepted

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

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

print(B[0])

Submission status: Accepted

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

inputs = deque(raw_input().split())
q = deque()
while len(inputs):
    op = inputs.popleft()
    if op == '+':
        q.append(q.pop() + q.pop())
    elif op == '-':
        v1 = q.pop()
        v2 = q.pop()
        q.append(v2 - v1)
    elif op == '*':
        q.append(q.pop() * q.pop())
    else:
        q.append(int(op))

print q.pop()

Submission status: Accepted

Solution code:
l = []
o = ["+", "-", "*"]
for i in input().split():
  if i in o:
    t = eval("{0}{1}{2}".format(l[-2], i, l[-1]))
    l.pop(-1)
    l[-1] = t
  else: l += [int(i)]
print(*l)

Submission status: Accepted

Solution code:
A = input().split()
S, top = [0], 0


def push(x):
    global top, S
    top += 1
    if len(S) < top + 1:
        S.append(x)
    else:
        S[top] = x


def pop(x):
    global top, S
    top -= 2
    if x == "+":
        push(int(S[top + 1]) + int(S[top + 2]))
    elif x == "-":
        push(int(S[top + 1]) - int(S[top + 2]))
    elif x == "*":
        push(int(S[top + 1]) * int(S[top + 2]))


for i in range(len(A)):
    if str(A[i]).isdigit():
        push(int(A[i]))
    else:
        pop(A[i])
print(S[1])

Submission status: Accepted

Solution code:
def reverse_polish_calculator(s):
    """Calculate a reverse polish notation s.
    + - * operators can be used in s. Only positive integer is
    supported for operand.

    >>> reverse_polish_calculator("1 2 +")
    3
    >>> reverse_polish_calculator("1 2 + 3 4 - *")
    -3
    """
    def calc(val1, op, val2):
        if op == '+':
            return val1 + val2
        elif op == '-':
            return val1 - val2
        elif op == '*':
            return val1 * val2
        else:
            raise ValueError()

    stack = []
    for c in s.split():
        if c.isnumeric():
            stack.append(int(c))
        else:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(calc(v1, c, v2))

    return stack.pop()


def run():
    s = input()
    print(reverse_polish_calculator(s))


if __name__ == '__main__':
    run()

Submission status: Accepted

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

stk = []
opr = ['+', '-', '*']

for e in seq:
    if e in opr:
        if e == '+':
            res = stk[-2] + stk[-1]
        elif e == '-':
            res = stk[-2] - stk[-1]
        elif e == '*':
            res = stk[-2] * stk[-1]
        stk = stk[:-2] + [res]
    else:
        stk.append(int(e))

print(stk[0])

Submission status: Accepted

Solution code:
def calculator(op, x, y):
    if op == '+':
        return x + y
    elif op == '-':
        return y - x
    else:
        return x * y


raw = [r for r in input().split()]
for i in range(len(raw)):
    try:
        raw[i] = int(raw[i])
    except:
        continue

arr = []
buff = 0
for i in range(len(raw)):
    if isinstance(raw[i], int):
        arr.append(raw[i])
    else:
        buff = calculator(raw[i], arr.pop(), arr.pop())
        arr.append(buff)

print(*arr)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
rpn = lambda s: int(reduce(
    lambda x, y: (
        x[:-2] + [str(eval(x[-2]+y[0]+x[-1]))] if y in '+-*'
        else x + [y]
    ), s.split(), []
)[0])
print(rpn(input()))

Submission status: Accepted

Solution code:
print((lambda s: int(__import__('functools').reduce(
    lambda x, y: (
        x[:-2] + [str(eval(x[-2]+y[0]+x[-1]))] if y in '+-*'
        else x + [y]
    ), s.split(), []
)[0]))(input()))

Submission status: Accepted

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

Submission status: Accepted

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

operater=["+","*","-","/"]
cal=[]
k=0
for i in range(len(d)):
    if d[i] not in operater:
        cal.append(int(d[i]))
        k+=1
    else:
        j=operater.index(d[i])
        if j==0:
            x=cal[k-1]+cal[k-2]
        elif j==1:
            x=cal[k-1]*cal[k-2]
        elif j==2:
            x=cal[k-2]-cal[k-1]
        else:
            x=cal[k-2]/cal[k-1]
        cal.pop()
        cal.pop()
        cal.append(x)
        print
        k-=1
print(cal[0])

Submission status: Accepted

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


for i in A:
    if i == '+' or i == '-' or i == '*':
        a = S.pop()
        b = S.pop()
        if i == '+': S.append(b+a)
        elif i == '-': S.append(b-a)
        else: S.append(b*a)
    else:
        x = int(i)
        S.append(x)
    #print(S)

print(S[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

A=input().split()
i=0
for j in range(len(A)):
    if A[i]=="+":
        r=int(A[i-2])+int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    if A[i]=="-":
        r=int(A[i-2])-int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    if A[i]=="*":
        r=int(A[i-2])*int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    i+=1

print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cal(ope,a,b):
    if ope=="+":
        x=a+b
    elif ope=="-":
        x=a-b
    elif ope=="*":
        x=a*b
    return x

lst=input().split()
stack=[]
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": pass
    else:
        lst[i]=int(lst[i])
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": 
        a=stack.pop()
        b=stack.pop()
        c=cal(lst[i],b,a)
        stack.append(c)
    else:
        stack.append(lst[i])
print(stack[0])

Submission status: Accepted

Solution code:
import sys
a = list(input().split())
stack = []
for i in range(len(a)):
    n = len(stack)
    if a[i] == '+':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) + int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '-':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 - tmp_1
        stack.append(tmp)
        
    elif a[i] == '*':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) * int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '/':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 / tmp_1
        stack.append(tmp)
    else:
        stack.append(int(a[i]))
print(stack[0])

Submission status: Accepted

Solution code:
#課題3-A 16D8102014J 井口和人　4/27
#python
a=input().split()

stack=[]

for i in a:
    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:
#! python3
# stack.py

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

def calc(op):
    global stack
    if op == '+':
        return stack.pop()+stack.pop()
    elif op == '-':
        return -1 * stack.pop()+stack.pop()
    elif op == '*':
        return stack.pop()*stack.pop()

for s in symbols:
    if s in ['+', '-', '*']:
        stack.append(calc(s))
    else:
        stack.append(int(s))

print(stack.pop())

Submission status: Accepted

Solution code:
def kei(a,i,x,y):
	if a[i]=="+":
		st=x+y
		#print("+")
	elif a[i]=="-":
		st=y-x
		#print("-")
	elif a[i]=="*":
		st=x*y
		#print("*") 
	return st


a=[]
stac=[]
a=list(input().split())
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		#print(stac)
	else:
		x=stac.pop()
		y=stac.pop()
		stac.append(kei(a,i,x,y))
		
print(stac[0])

Submission status: Accepted

Solution code:
l=list(input().split())  ##文字も数字も入る
stack=[]

for x in l: ##リストの長さ文だけ繰り返し
    if x in ['+','-','*']: ##←知らなかった判定方法
        t=str(stack.pop()) ##末尾取り出し
        r=str(stack.pop())
        c=r+x+t
        stack+=[int(eval(c))] ##eval:入力した式の入力

    else:
        stack+=[int(x)] ##[]の意味?>リストに追加

print(stack.pop())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:04:29 2018
ALDS1-3a
@author: maezawa
"""
maxn=200
s = input().split()
st = [0 for _ in range(maxn)]
top = 0

for i in range(len(s)):
    c = s.pop(0)
    if c == '+':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a + b
        top += 1
        st[top] = ans
    elif c == '-':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a - b
        top += 1
        st[top] = ans
    elif c == '*':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a * b
        top += 1
        st[top] = ans
    else:
        top += 1
        st[top] = int(c)
print(st[top])

Submission status: Accepted

Solution code:
s = input().split()
st = []

for i in range(len(s)):
    c = s.pop(0)
    if c == '+':
        b = st.pop(0)
        a = st.pop(0)
        ans = a + b
        st.insert(0,ans)
    elif c == '-':
        b = st.pop(0)
        a = st.pop(0)
        ans = a - b
        st.insert(0,ans)
    elif c == '*':
        b = st.pop(0)
        a = st.pop(0)
        ans = a * b
        st.insert(0,ans)
    else:
        st.insert(0, int(c))

print(st.pop(0))

Submission status: Accepted

Solution code:
a=input().split()
operator={
  '+':(lambda x,y:x+y),
  '-':(lambda x,y:x-y),
  '*':(lambda x,y:x*y),
  '/':(lambda x,y:float(x)/y)
}
stack=[]
for i,j in enumerate(a):
  if j not in operator.keys():
    stack.append(int(j))
    continue
  y=stack.pop()
  x=stack.pop()
  stack.append(operator[j](x,y))
print(stack[0])

Submission status: Accepted

Solution code:
#16D8103014C 安藤 陸人
#3_A
x = input().split()
flag = 0
j = -1
y = []
for i in range(len(x)):
    j = len(y) -1
    if x[i] == "+":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b+a)
    elif  x[i] == "-":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b-a)
    elif x[i] == "*":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b*a)
    else:
        y.append(int(x[i]))
print(y[0])