#C12913. Evaluate Reverse Polish Notation Expression
Evaluate Reverse Polish Notation Expression
Evaluate Reverse Polish Notation Expression
Given a valid mathematical expression in Reverse Polish Notation (RPN), compute and output its value as a floating point number.
The expression is provided as a single line of space-separated tokens. Operands are numbers (which may be negative) and operators are one of the following: +, -, *, or /.
The evaluation should follow the standard RPN rules where an operator applies to the two most recent operands on the stack. In case of division, perform floating-point division. It is guaranteed that the provided expression is valid and does not contain any division by zero.
Note: The result must be computed using standard arithmetic rules and printed as a floating point number.
inputFormat
The input consists of a single line read from standard input (stdin
). This line contains a complete RPN expression, where tokens (operands and operators) are separated by spaces.
outputFormat
Output a single line to standard output (stdout
) containing the result of evaluating the RPN expression as a floating point number.
3 4 +
7.0