#K93567. Expression Evaluator

    ID: 38448 Type: Default 1000ms 256MiB

Expression Evaluator

Expression Evaluator

You are given a string representing a mathematical expression that contains positive integers and the four basic arithmetic operators: +, -, *, and /. The expression should be evaluated by following the standard operator precedence rules, i.e., the multiplication and division operators have higher precedence than addition and subtraction. In other words, the expression is evaluated according to the formula:

$$\text{result} = \sum (\text{term}_{i})$$

where each term with multiplication or division is calculated first. Note that division is performed with integer truncation (i.e., any fractional part is discarded). For example:

  • "3+5*2" is evaluated as 3 + (5*2) = 13.
  • "10+20/5" is evaluated as 10 + (20/5) = 14.
  • "8-3*2+4" is evaluated as 8 - (3*2) + 4 = 6.

Your task is to implement a program that reads a single line expression from standard input and outputs the evaluated integer result to standard output.

inputFormat

The input consists of a single line containing a valid mathematical expression. The expression will only include positive integers and the operators +, -, *, and / without any spaces.

outputFormat

Output the integer result of evaluating the expression. The division operator should perform integer division (truncating towards zero).

## sample
3+5
8

</p>