#C1463. Arithmetic Expression Evaluator

    ID: 44300 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluator

Arithmetic Expression Evaluator

Given a mathematical expression as a string, evaluate the expression according to the standard arithmetic operator precedence. The expression may include non-negative integers, the operators +, -, *, /, and parentheses. Use integer division (i.e. rounding towards zero) for division operations.

For example, for the expression 3+2*2, the correct answer is 7. Your task is to parse and evaluate such expressions while respecting the order of operations:

  • Parentheses
  • Multiplication and Division
  • Addition and Subtraction

It is guaranteed that the given expression is valid. Consider using the Shunting-yard algorithm or stack-based evaluation.

inputFormat

The input consists of a single line containing a mathematical expression. The expression may include digits, spaces, and the characters +, -, *, /, and parentheses.

outputFormat

Output a single integer which is the result of evaluating the given expression.

## sample
3+2*2
7