#C4493. Evaluate a Mathematical Expression
Evaluate a Mathematical Expression
Evaluate a Mathematical Expression
Given a string representing a mathematical expression, you are required to compute its value by simulating a simple parser. The expression may contain non-negative integers, the operators +
, -
, *
, /
(where /
is integer division), and parentheses ( )
. Operator precedence follows the standard rules:
- Multiplication and division have higher precedence than addition and subtraction.
- Operators with the same precedence are evaluated from left to right (associativity).
The answer should be computed using the algorithm similar to the Shunting Yard algorithm.
Note: All divisions are integer divisions, meaning that the result of 7/2 is 3 because it discards the remainder.
inputFormat
The input is given via standard input (stdin) as a single line representing the mathematical expression. The expression will only contain non-negative integers, the operators +
, -
, *
, /
, and possibly parentheses.
outputFormat
Output the evaluated result as an integer via standard output (stdout).
## sample3+5*2
13