#C6556. Evaluate Arithmetic Expression

    ID: 50329 Type: Default 1000ms 256MiB

Evaluate Arithmetic Expression

Evaluate Arithmetic Expression

Given a string representing an arithmetic expression, your task is to evaluate the expression and output its integer result. The expression can include non-negative integers, the operators +, -, *, /, and parentheses ( ). Note that division between two integers should truncate toward zero.

The operator precedence is defined as follows:

  • Multiplication and division (* and /) have higher precedence than addition and subtraction (+ and -).
  • Parentheses can be used to override the default precedence.

For example, the expression 3 + 2 * 2 should be evaluated as 3 + (2 * 2) = 7, and the expression (3 + 2) * 2 should be evaluated as (3 + 2) * 2 = 10.

The evaluation must follow the standard rules of arithmetic, and if there is any division, the result of the division should be truncated towards zero (i.e., rounded toward zero).

inputFormat

The input consists of a single line that contains the arithmetic expression as a string.

Example Input:

3 + 2 * 2

outputFormat

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

Example Output:

7
## sample
3+2
5