#C8818. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string expression
that represents a mathematical expression. The expression contains non-negative integers and two operators: + and *. There are no spaces in the string. You need to compute the value of the expression following the standard order of operations, i.e. multiplication takes precedence over addition.
In mathematical terms, if the expression is given by:
$E = a_1 + a_2 + \cdots + a_k$, where each $a_i$ is a product of one or more integers connected by $\times$ (i.e. $a_i = n_{i1} \times n_{i2} \times \cdots \times n_{im}$), then the answer is:
$\text{result} = \sum_{i=1}^{k} \left( \prod_{j=1}^{m} n_{ij} \right)$
Examples:
- Input:
2+3*4
→ Output:14
- Input:
5*6+7
→ Output:37
- Input:
1+2*3+4*5+6
→ Output:33
inputFormat
The input consists of a single line containing a string expression
composed of digits and the characters '+' and '*'.
outputFormat
Output a single integer which is the evaluation of the expression according to the rules of operator precedence.
## sample3+2
5