#C10437. Reverse Polish Notation Evaluator
Reverse Polish Notation Evaluator
Reverse Polish Notation Evaluator
You are given an expression in Reverse Polish Notation (RPN). In this notation, every operator follows all of its operands. For example, the expression 3 4 + is equivalent to 3 + 4 in conventional notation. Your task is to evaluate the RPN expression and output the integer result.
The expression is composed of integers and the operators \(+, -, \times, \div\). Note that division between two integers should truncate toward zero. It is guaranteed that the provided expression is valid and will result in a single integer value.
Example:
- Input:
3 4 +
- Output:
7
inputFormat
The input consists of a single line containing a valid Reverse Polish Notation expression. Tokens in the expression are separated by single spaces.
Each token is either an integer or one of the operators: +
, -
, *
, or /
.
outputFormat
Output the integer result after evaluating the RPN expression. The result should be printed to the standard output.
## sample3 4 +
7