#C13374. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a mathematical expression that consists of non-negative integers, the addition operator +
, and the multiplication operator *
. The expression may include arbitrary spaces. Your task is to evaluate the expression according to the standard operator precedence: multiplication is performed before addition.
Note: The expression will only contain integers, +
, and *
. There will be no subtraction, division, or parentheses in the expression.
The mathematical formula can be summarized as follows:
\( result = \sum_{i=1}^{n} \prod_{j=1}^{m_i} a_{ij} \)
where each aij
is a non-negative integer.
inputFormat
The input consists of a single line that contains the expression as a string. The expression may include spaces.
Example: 3 + 2 * 2
outputFormat
Output a single integer which is the result of evaluating the expression.
## sample3 + 2 * 2
7