← 返回 amazon 的题目列表Basic Calculator with Postfix Notation
类型:online_judge
Problem: Basic Calculator with Postfix Notation
Given a postfix expression, also known as Reverse Polish Notation, evaluate its value.
The expression consists of integers and operators separated by spaces.
Supported operators:
+
-
*
/
Division should truncate toward zero. For example:
7 / 3 = 2
-7 / 3 = -2
You may assume the expression is valid and there is no division by zero.
Input Format
token_1 token_2 ... token_m
Output Format
result
Constraints
1 <= m <= 100000
Operands fit in 32-bit signed integers.
Intermediate and final results fit in 64-bit signed integers.
Example
Input:
2 1 + 3 *
Output:
9
Example
Input
2 1 + 3 *
Output
9