Problem:


未熟者の数式

博士 : ピーター君、ついにやったよ。

ピーター : またですか。今度はどんなくだらない発明ですか。

博士 : ついに数式を計算機で処理する画期的な方法を思いついたんだ。この表をみてごらん。

通常の記法博士の「画期的な」記法

1 + 21 2 +

3 * 4 + 73 4 * 7 +

10 / ( 2 - 12 )	10 2 12 - /

( 3 - 4 ) * ( 7 + 2 * 3 )3 4 - 7 2 3 * + *

ピーター : はぁ。

博士 : ふっふっふ。これだけでは、未熟者の君には何のことだかわからないだろうねえ。ここからが肝心なんじゃ。

ピーター : っていうか・・・。

博士 : 計算機にはスタックというデータ構造があることは君も知っているね。ほれ、「先入れ後出し」のあれじゃよ。

ピーター : はい。知ってますが、あの・・・。

博士 : この画期的な記法はあのスタックを使うんじゃ。例えばこの 10 2 12 - / だが、次のように処理する。

処理対象10212-/

        ↓↓↓↓2-12↓10/-10

スタック

 

.

.

10

 

.

2

10

 

12

2

10

 

.

-10

10

 

.

.

-1

博士 : どうじゃな。括弧も演算子の優先順位も気にする必要がないじゃろう？語順も「10 を 2 から 12 を引いたもので割る。」となり、何となく彼の極東の島国の言葉、日本語と似ておるじゃろうて。
       この画期的な発明さえあれば、我が研究室は安泰じゃて。ファファファ。

ピーター : っていうか博士。これって日本にいたとき会津大学の基礎コースで習いましたよ。「逆ポーランド記法」とかいって、みんな簡単にプログラムしてました。

博士 : ・・・。

ということで、ピーター君に変わって博士に、このプログラムを教える事になりました。「逆ポーランド記法」で書かれた数式を入力とし、計算結果を出力するプログラムを作成してください。

入力

複数のデータセットが与えられます。各データセットでは、逆ポーランド記法による数式（整数と演算記号が空白文字１文字（半角）で区切られた80文字以内の文字列）が １ 行に与えられます。
ある値を 0 や 0 に限りなく近い値で割るような数式は与えられません。

データセットの数は 50 を超えません。

出力

各データセットごとに、計算結果（実数）を１行に出力してください。なお、計算結果は 0.00001 以下の誤差を含んでもよい。

Sample Input

10 2 12 - /
3 4 - 7 2 3 * + *
-1 -2 3 + +

Output for the Sample Input

-1.000000
-13.000000
0.000000



Sample input:
10 2 12 - /
3 4 - 7 2 3 * + *
-1 -2 3 + +


Sample output:
-1.000000
-13.000000
0.000000

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		stack = []
		st = map(str, raw_input().split())
		for s in st:
			if s == "-":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) / stack.pop())
			else:
				stack.append(float(s))
	
		print stack[0]
	except:
		break

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		stack = []
		st = map(str, raw_input().split())
		for s in st:
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			else:
				stack.append(int(s))
	
		print "%.6f" % (stack[0])
	except:
		break

Submission status: Wrong Answer

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

import sys


def calc_inverse_polish_notation_string(s):
    tokens = [token for token in s.split(' ') if token != '']
    stack = []
    for token in tokens:
        if token in ['+', '-', '*', '/']:
            val2 = stack.pop()
            val1 = stack.pop()
            result = eval("%s %s %s" % (val1, token, val2))
            stack.append(result)
        else:
            stack.append(token)

    return stack[0]  # if len(stack) != 1, it should throw an exception


def main():
    for line in sys.stdin.readlines():
        print(calc_inverse_polish_notation_string(line))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}
    
    
def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


# Receive input
formula = input()
# split with ' '
ops = formula.split()

stack = []

for op in ops:
    if is_float_str(op)["is_float"]:
        stack.append(is_float_str(op)["val"])
    elif op in ['+', '-', '*', '/']:
        stack.append(compute(op, stack.pop(), stack.pop()))

if len(stack) == 1:
    print(stack[0])

Submission status: Wrong Answer

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


# Receive input
formula = '-1 -2 3 + +'
# split with ' '
ops = formula.split()

stack = []

for op in ops:
    if is_float_str(op)["is_float"]:
        stack.append(is_float_str(op)["val"])
    elif op in ['+', '-', '*', '/']:
        stack.append(compute(op, stack.pop(), stack.pop()))

if len(stack) == 1:
    print(str(stack[0]) + '\n')

Submission status: Wrong Answer

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


# Receive input
formula = input()
# split with ' '
ops = formula.split()

stack = []

for op in ops:
    if is_float_str(op)["is_float"]:
        stack.append(is_float_str(op)["val"])
    elif op in ['+', '-', '*', '/']:
        stack.append(compute(op, stack.pop(), stack.pop()))

if len(stack) == 1:
    print(str(stack[0]) + '\n')

Submission status: Wrong Answer

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


def get_input():
    while True:
        try:
            yield input()
        except EOFError:
            break


# split with ' '
formulas = list(get_input())
for (i, formula) in enumerate(formulas, 0):
    formulas[i] = formula.split(' ')
stack = []

for formula in formulas:
    for elm in formula:
        if is_float_str(elm)["is_float"]:
            stack.append(is_float_str(elm)["val"])
        elif elm in ['+', '-', '*', '/']:
            stack.append(compute(elm, stack.pop(), stack.pop()))

if len(stack) == 1:
    print(str(stack[0]) + '\n')

Submission status: Wrong Answer

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


def get_input():
    while True:
        try:
            yield input()
        except EOFError:
            break


# split with ' '
formulas = list(get_input())
for (i, formula) in enumerate(formulas, 0):
    formulas[i] = formula.split(' ')
stack = []

for formula in formulas:
    stack = []
    for elm in formula:
        if is_float_str(elm)["is_float"]:
            stack.append(is_float_str(elm)["val"])
        elif elm in ['+', '-', '*', '/']:
            stack.append(compute(elm, stack.pop(), stack.pop()))
    if len(stack) == 1:
        print(str(stack[0]))

Submission status: Wrong Answer

Solution code:
# AOJ 0087 Strange Mathematical Expression
# Python3 2018.6.14 bal4u

class Stack:
	def __init__(self):
		self.items = []
	def push(self, item):
		self.items.append(item)
	def pop(self):
		return self.items.pop()
	def size(self):
		return len(self.items)

s = Stack()
while True:
	try:
		a = list(input().split())
	except EOFError:
		break

	for token in a:
		if token in ['+','-','*','/']:
			v1, v2 = s.pop(), s.pop()
			if token == '+':
				v2 += v1
			elif token == '-':
				v2 -= v1
			elif token == '*':
				v2 *= v1
			else:
				v2 /= v1
			s.push(v2)
		else:
			s.push(int(token))
print(s.pop())

Submission status: Wrong Answer

Solution code:
import sys
for line in sys.stdin.readlines():
    stack=[]
    for a in line.strip().split():
        if a=="+":
            a=stack.pop()+stack.pop()
        elif a=="-":
            a=-(stack.pop()-stack.pop())
        elif a=="*":
            a=stack.pop()*stack.pop()
        elif a=="/":
            a=stack.pop()/stack.pop()
        stack.append(float(a))
    print stack[0]

Submission status: Wrong Answer

Solution code:
import sys
for line in sys.stdin.readlines():
    stack=[]
    for a in line.strip().split():
        if a=="+":
            a=stack.pop()+stack.pop()
        elif a=="-":
            a=-(stack.pop()-stack.pop())
        elif a=="*":
            a=stack.pop()*stack.pop()
        elif a=="/":
            a=stack.pop()/stack.pop()
        stack.append(float(a))
    print "{:.6}".format(stack[0]+0)

Submission status: Wrong Answer

Solution code:
import sys
for line in sys.stdin.readlines():
    stack=[]
    for a in line.strip().split():
        if a=="+":
            a=stack.pop()+stack.pop()
        elif a=="-":
            a=-(stack.pop()-stack.pop())
        elif a=="*":
            a=stack.pop()*stack.pop()
        elif a=="/":
            a=stack.pop()/stack.pop()
        stack.append(float(a))
    print "{:.6f}".format(stack[0]+0)

Submission status: Wrong Answer

Solution code:
import sys
for line in sys.stdin:
	foo=map(str, line.strip().split())
	stack=[]
	while (foo!=[]):
		if foo[0]=='+':
			del foo[0]
			stack.append(int(stack.pop())+int(stack.pop()))
		elif foo[0]=='*':
			del foo[0]
			stack.append(int(stack.pop())*int(stack.pop()))
		elif foo[0]=='-':
			del foo[0]
			stack.append(-int(stack.pop())+int(stack.pop()))
		elif foo[0]=='/':
			del foo[0]
			stack.append(1.0/int(stack.pop())*int(stack.pop()))
		else:
			stack.append(foo.pop(0))
	print float(stack.pop())

Submission status: Wrong Answer

Solution code:
import sys
for line in iter(sys.stdin.readline, ""):
	foo=map(str, line.strip().split())
	stack=[]
	while (foo!=[]):
		if foo[0]=='+':
			del foo[0]
			stack.append(int(stack.pop())+int(stack.pop()))
		elif foo[0]=='*':
			del foo[0]
			stack.append(int(stack.pop())*int(stack.pop()))
		elif foo[0]=='-':
			del foo[0]
			stack.append(-int(stack.pop())+int(stack.pop()))
		elif foo[0]=='/':
			del foo[0]
			stack.append(1.0/int(stack.pop())*int(stack.pop()))
		else:
			stack.append(foo.pop(0))
	print float(stack.pop())

Submission status: Wrong Answer

Solution code:
while True:
    try:
        inp = map(str, raw_input().split())
        stuck = []
        for i in inp:
            if i == "+":
                stuck.append(int(stuck.pop(len(stuck)-2)) + int(stuck.pop(len(stuck)-1)) )
            elif i == "-":
                stuck.append(int(stuck.pop(len(stuck)-2)) - int(stuck.pop(len(stuck)-1)) )
            elif i == "*":
                stuck.append(int(stuck.pop(len(stuck)-2)) * int(stuck.pop(len(stuck)-1)) )
            elif i == "/":
                stuck.append(int(stuck.pop(len(stuck)-2)) / float(stuck.pop(len(stuck)-1)) )
            else:
                stuck.append(i)
        print stuck[0]
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        inp = map(str, raw_input().split())
        stuck = []
        for i in inp:
            if i == "+":
                stuck.append(int(stuck.pop(len(stuck)-2)) + int(stuck.pop(len(stuck)-1)) )
            elif i == "-":
                stuck.append(int(stuck.pop(len(stuck)-2)) - int(stuck.pop(len(stuck)-1)) )
            elif i == "*":
                stuck.append(int(stuck.pop(len(stuck)-2)) * int(stuck.pop(len(stuck)-1)) )
            elif i == "/":
                stuck.append(int(stuck.pop(len(stuck)-2)) / float(stuck.pop(len(stuck)-1)) )
            else:
                stuck.append(i)
        print float(stuck[0])
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
while 1:
	su = 0
	stack = []
	try:
		raw = raw_input().split()
	except:
		pass
	else:
		for s in raw:
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(int(s))
	
		print "%.6f" % (stack[0])

Submission status: Time Limit Exceeded

Solution code:
while 1:
	stack = []
	
	try:
		for s in raw_input().split():
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(int(s))
	
		print "%.6f" % (stack[0])
	except:
		pass

Submission status: Time Limit Exceeded

Solution code:
while 1:
	try:
		stack = []
		for s in raw_input().split():
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(float(s))
	
		print stack[0]
	except:
		pass

Submission status: Time Limit Exceeded

Solution code:
while 1:
	try:
		stack = []
		for s in map(str, raw_input().split()):
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(float(s))
	
		print stack[0]
	except:
		pass

Submission status: Time Limit Exceeded

Solution code:
while 1:
	try:
		stack = []
		for s in map(str, raw_input().split()):
			if s == "-":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) / stack.pop())
			else:
				stack.append(float(s))
	
		print stack[0]
	except:
		pass

Submission status: Time Limit Exceeded

Solution code:
while 1:
	try:
		stack = []
		st = map(str, raw_input().split())
		for s in st:
			if s == "-":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) / stack.pop())
			else:
				stack.append(float(s))
	
		print stack[0]
	except:
		pass

Submission status: Accepted

Solution code:
import sys

def isNum(a) :
    try:
        int(a)
    except:
        return False
    return True

for line in sys.stdin:
    stack = []
    task = line.strip().split(" ") ;
    for i in range(0, len(task) ) :
        if isNum(task[i]) :
            stack.append(task[i])
        elif len(stack) != 0 :
            stack.append( str( eval( stack.pop(-2) + task[i] + stack.pop(-1) ) ) )
    print("{:6f}".format(float(stack[0])))

Submission status: Accepted

Solution code:
while(1):
    try:
        a = [i for i in input().split()]
        stack = []
        l = len(stack)
        for i in a:
            if i == "+":
                x = stack[l-2]
                y = stack[l-1]
                stack.pop()
                stack.pop()
                stack.append(x+y)
            elif i == "-":
                x = stack[l-2]
                y = stack[l-1]
                stack.pop()
                stack.pop()
                stack.append(x-y)
            elif i == "*":
                x = stack[l-2]
                y = stack[l-1]
                stack.pop()
                stack.pop()
                stack.append(x*y)
            elif i == "/":
                x = stack[l-2]
                y = stack[l-1]
                stack.pop()
                stack.pop()
                stack.append(x/y)
            else:
                stack.append(float(i))
        print("{:.6f}".format(stack[0]))
    except EOFError:
        break

Submission status: Accepted

Solution code:
def ev( a, b, oper ):
    if oper == '+': return a+b
    if oper == '-': return a-b
    if oper == '*': return a*b
    if oper == '/': return a/b
    return 0

while True:
    try:
        expr = raw_input().split()
    except EOFError:
        break
    stack = []
    for c in expr:
        try:
            stack.append( float(c) )
        except ValueError:
            a, b = stack.pop(), stack.pop()
            stack.append( ev(b, a, c) )
    print stack.pop()

Submission status: Accepted

Solution code:
#! -*- coding: utf-8-unix -*-
import sys

if __name__=='__main__':
  lines = [x.strip() for x in sys.stdin.readlines() if x != '' and x != '\n']
  for line in lines:
    cs = line.split()
    stack = []
    res = 0.0
    for c in cs:
      res = ''
      if not(c == '-' or c == '+' or c == '*' or c == '/'):
        res = float(c)
      else:
        s1, s2 = stack.pop(), stack.pop()
        if c == '-':
          res = s2 - s1
        elif c == '+':
          res = s2 + s1
        elif c == '*':
          res = s2 * s1
        elif c == '/':
          res = s2 / s1
      stack.append(res)
    assert(len(stack) == 1)
    print stack[0]

Submission status: Accepted

Solution code:
def solve(st):
    d = st.split()
    l = []
    for i in xrange(len(d)):
        if d[i] == "+":
            l.append(l.pop()+l.pop())
        elif d[i] == "-":
            l.append(-l.pop()+l.pop())
        elif d[i] == "*":
            l.append(l.pop()*l.pop())
        elif d[i] == "/":
            l.append(1/l.pop()*l.pop())
        else:
            l.append(float(d[i]))
    return l[0]

while True:
    try:
        s = raw_input()
        print solve(s)
    except:
        break

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

from collections import deque
import operator

func = {'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.truediv }

for line in f:
    stack = deque()
    for element in line.strip().split():
        if element in func:
            b = stack.pop()
            a = stack.pop()
            stack.append(func[element](a, b))
        else:
            stack.append(float(element))
    print('{:.6f}'.format(stack[0]))

Submission status: Accepted

Solution code:
while 1:
	try:
		stack = []
		for s in raw_input().split():
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			else:
				stack.append(float(s))
	
		print "%.6f" % (stack[0])
	except:
		break

Submission status: Accepted

Solution code:
import sys


def calc_inverse_polish_notation_string(s):
    tokens = [token for token in s.split(' ') if token != '']
    stack = []
    for token in tokens:
        if token in ['+', '-', '*', '/']:
            val2 = stack.pop()
            val1 = stack.pop()
            result = eval("%s %s %s" % (val1, token, val2))
            stack.append(result)
        else:
            stack.append(token)

    return stack[0]  # if len(stack) != 1, it should throw an exception


def main():
    for line in sys.stdin.readlines():
        print(calc_inverse_polish_notation_string(line.strip()))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def doc_string():
    """
    I can fly.
    """

while True:
    list = []
    stack = []
    if __name__ == "__main__":
        try:
            list = raw_input().split()
        except EOFError:
            break
            
        for var in list:
            try:
                stack.append(float(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)
                if var == "/":
                    a = stack.pop()
                    b = stack.pop()
                    stack.append(b / a)

        print stack.pop()

Submission status: Accepted

Solution code:
while 1:
    try:
        l=map(str,raw_input().split())
        s=[]
        for i in l:
            if i=='+':
                s.append(s.pop(-2)+s.pop(-1))
            elif i=='-':
                s.append(s.pop(-2)-s.pop(-1))
            elif i=='*':
                s.append(s.pop(-2)*s.pop(-1))
            elif i=='/':
                s.append(s.pop(-2)/s.pop(-1))
            else:
                s.append(float(i))
        print s[0]
    except:
        break
exit()

Submission status: Accepted

Solution code:
from collections import deque
import operator

import sys

stack = deque()
operators = {
    '+': operator.add,
    '-': operator.sub,
    '*': operator.mul,
    '/': operator.truediv
}

for line in sys.stdin:
    for term in line.split():
        if term in operators:
            a, b = stack.pop(), stack.pop()
            stack.append(operators[term](b, a))
        else:
            stack.append(float(term))
    print(stack.pop())

Submission status: Accepted

Solution code:
def calc(a,b,c):
    if c=="+":
        return a+b
    if c=="-":
        return a-b
    if c=="*":
        return a*b
    if c=="/":
        return a/b

while(1):
    try:
        wlist=raw_input().split()
        stack=[]
        for c in wlist:
            if c in "+-*/":
                b=stack.pop()
                a=stack.pop()
                stack.append(calc(a,b,c))
            else:
                stack.append(float(c))
        print stack[0]
    except:
        break

Submission status: Accepted

Solution code:
import sys
def line():return sys.stdin.readline().strip()

ops = {"+":lambda a,b:b + a,
     "-":lambda a,b:b - a,
     "*":lambda a,b:b * a,
     "/":lambda a,b:b / a}
while True:
    try:
        stack = []
        for s in line().split():
            if s in ops:
                stack.append(ops[s](stack.pop(),stack.pop()))
            else:
                stack.append(int(s))
        print(stack[0])
    except:
        break

Submission status: Accepted

Solution code:
import sys
st=[]
for a in sys.stdin:
    s=a.split()
    del st[:]
    for i in range(len(s)):
        if s[i] in ['+','-','*','/']:
            a=st.pop(-1)
            b=st.pop(-1)
            if s[i]=='+':c=b+a
            elif s[i]=='-':c=b-a
            elif s[i]=='*':c=b*a
            else: c=1.*b/a
            st.append(c)
        else:
            st.append(float(s[i]))
    print st[0]

Submission status: Accepted

Solution code:
while 1:
    try:s=list(input().split())
    except:break
    a=[]
    for x in s:
        if x in ['+','-','*','/']:
            c,b=str(a.pop()),str(a.pop())
            b+=x+c
            a+=[float(eval(b))]
        else:a+=[float(x)]
    print(a.pop())

Submission status: Accepted

Solution code:
while 1:
    try:s=list(input().split())
    except:break
    a=[]
    for x in s:
        if x in ['+','-','*','/']:
            c,b=str(a.pop()),str(a.pop())
            a+=[float(eval(b+x+c))]
        else:a+=[float(x)]
    print(*a)

Submission status: Accepted

Solution code:
def invpol(f):
    s = []
    for c in f:
        if c == '+':
            a = s.pop()
            s.append(s.pop() + a)
        elif c == '-':
            a = s.pop()
            s.append(s.pop() - a)
        elif c == '*':
            a = s.pop()
            s.append(s.pop() * a)
        elif c == '/':
            a = s.pop()
            s.append(s.pop() / a)
        else:
            s.append(int(c))
    return(s[0])

while True:
    try:
        f = input().strip().split()
        print("%.6f" % invpol(f))

    except EOFError:
        break

Submission status: Accepted

Solution code:
exec("try:s=list();[[[s.append(eval('{2}{1}{0}'.format(s.pop(),i,s.pop()))if(i in'+-*/')else i)for i in input().split(' ')]and print(s.pop())]for x in __import__('itertools').count()]\nexcept:pass")

Submission status: Accepted

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

import sys
import os
import math

for s in sys.stdin:
    lst = s.split()

    # stack
    S = []

    for c in lst:
        if c == '+':
            a = S.pop()
            b = S.pop()
            S.append(b + a)
        elif c == '-':
            a = S.pop()
            b = S.pop()
            S.append(b - a)
        elif c == '*':
            a = S.pop()
            b = S.pop()
            S.append(b * a)
        elif c == '/':
            a = S.pop()
            b = S.pop()
            S.append(b / a)
        else:
            S.append(float(c))
    print(S[0])

Submission status: Accepted

Solution code:
import re
while True:
    try:
       f = input().split()
    except:
        break
    stack = []
    for c in f:
        if re.match("-*[0-9]", c) is None:
            b, a = str(stack.pop()), str(stack.pop())
            stack.append(float(eval(a+c+b)))
        else:
            stack.append(c)
    print(stack[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0087
"""
import sys


def eval_rpn(data):
    result = 0
    S = []
    for d in data:
        # print('d = {}'.format(d))
        if d == '+':
            y = S.pop()
            x = S.pop()
            S.append(x+y)
        elif d == '-':
            y = S.pop()
            x = S.pop()
            S.append(x-y)
        elif d == '*':
            y = S.pop()
            x = S.pop()
            S.append(x*y)
        elif d == '/':
            y = S.pop()
            x = S.pop()
            S.append(x/y)
        else:
            S.append(int(d))
    return S[0]


def main(args):
    for line in sys.stdin:
        data = line.strip().split()
        result = eval_rpn(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def Calculate_RPN(L):
    St = []
    for i in L:
        if i == '+':
            b, a = float(St.pop()), float(St.pop())
            St.append(a+b)
        elif i == '-':
            b, a = float(St.pop()), float(St.pop())
            St.append(a-b)
        elif i == '*':
            b, a = float(St.pop()), float(St.pop())
            St.append(a*b)
        elif i == '/':
            b, a = float(St.pop()), float(St.pop())
            St.append(a/b)
        else:
            St.append(i)

    return St[0]


while True:
    try:
        s = raw_input().split()

    except EOFError:
        break

    print Calculate_RPN(s)

Submission status: Accepted

Solution code:
# Aizu Problem 0087: Strange Mathematical Expression
#
import sys, math, os

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


def upn(inputs):
    # inverse polish notation
    res = 0
    stack = []
    for inp in inputs:
        if inp in ['+', '-', '*', '/']:
            b = stack.pop()
            a = stack.pop()
            c = str(eval(a + inp + b))
            stack.append(c)
        else:
            stack.append(inp)
    return float(stack[0])

    
for line in sys.stdin:
    print("%.6f" % upn(line.split()))

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 a=[]
 for p in e.split():
  if p in'+-*/':t=a.pop();a+=[str(eval(a.pop()+p+t))]
  else:a+=[p]
 print(*a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val2 + val1
    elif operand == "-":
        return val2 - val1
    elif operand == "*":
        return val2 * val1
    elif operand == "/":
        return val2 / val1


def get_input():
    while True:
        try:
            yield input()
        except EOFError:
            break


if __name__ == '__main__':
    # split with ' '
    formulas = list(get_input())
    for (i, formula) in enumerate(formulas, 0):
        formulas[i] = formula.split(' ')
    stack = []

    for formula in formulas:
        stack = []
        for elm in formula:
            if is_float_str(elm)["is_float"]:
                stack.append(is_float_str(elm)["val"])
            elif elm in ['+', '-', '*', '/']:
                stack.append(compute(elm, stack.pop(), stack.pop()))
        if len(stack) == 1:
            print(format(stack[0], '.6f'))

Submission status: Accepted

Solution code:
while True:
    try:
        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)
            elif inp == "/":
                x = stack.pop()
                y = stack.pop()
                stack.append(y/x)
            else:
                stack.append(float(inp))

        print(*stack)
    except:
        break

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    p = N[l].split()
    s = []
    for i in range(len(p)):
        if p[i] == "+":
            a = float(s.pop())
            b = float(s.pop())
            s.append(str(b+a))
        elif p[i] == "-":
            a = float(s.pop())
            b = float(s.pop())
            s.append(str(b-a))
        elif p[i] == "*":
            a = float(s.pop())
            b = float(s.pop())
            s.append(str(b*a))
        elif p[i] == "/":
            a = float(s.pop())
            b = float(s.pop())
            s.append(str(b/a))
        else:
            s.append(p[i])
    print(s[0])

Submission status: Accepted

Solution code:
while True:
  try:
    ss = input().split()
    stack = []

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

    print(stack[0])

  except EOFError:
    break