#C14284. Evaluate Arithmetic Expression

    ID: 43916 Type: Default 1000ms 256MiB

Evaluate Arithmetic Expression

Evaluate Arithmetic Expression

You are given a string representing an arithmetic expression that consists of non-negative integers and the operators +, -, *, and /. The expression may contain spaces. Your task is to compute the result of the expression following the usual operator precedence rules, where multiplication and division have higher precedence than addition and subtraction. Division should be performed as integer division, where the result is truncated towards zero.

Note: It is guaranteed that the expression is valid and that intermediate results fit within a 32-bit signed integer.

Example:

  • Input: 3+2*2 → Output: 7
  • Input: 3/2 → Output: 1
  • Input: 3+5 / 2 → Output: 5

inputFormat

The input consists of a single line containing the arithmetic expression as a string. The expression may contain spaces.

outputFormat

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

## sample
3+2*2
7