#K89082. Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
Given a string S
representing a valid arithmetic expression containing non-negative integers, operators +
, -
, *
, /
and parentheses ( )
, compute the result of the expression.
Note: Division between two integers should truncate toward zero. The expression is guaranteed to be valid and may contain spaces.
The calculation should respect the typical operator precedence rules. All the intermediate and final computations are performed with integer arithmetic.
For example, for the expression \( ( 2 + 3 ) \times 4 \) the result is 20.
inputFormat
The input consists of a single line containing the arithmetic expression S
.
Example:
3+2*2
outputFormat
Print a single integer which is the result of the evaluated expression.
Example:
7## sample
3+2*2
7