#K4236. Evaluate Mathematical Expression

    ID: 27070 Type: Default 1000ms 256MiB

Evaluate Mathematical Expression

Evaluate Mathematical Expression

You are given a mathematical expression as a string consisting of digits (0-9) and the operators + and *. The task is to evaluate the expression following the standard order of operations, i.e., multiplication is performed before addition.

In mathematical terms, if the expression is represented as:

E=t1+t2++tn,E = t_1 + t_2 + \cdots + t_n,

where each term is a product of factors:

$$t_i = a_{i1} \times a_{i2} \times \cdots \times a_{ik}, $$

then you should compute each product first and then add the results.

Note: The input expression will always be valid and will not contain whitespace.

Example:

  • Input: 3+2*2
  • Output: 7

inputFormat

The input consists of a single line containing the expression as a string.

Example:

3+2*2

outputFormat

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

Example:

7
## sample
3+2
5