#K67292. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a simple arithmetic expression that consists of non-negative integers and the operators +
and *
. The multiplication operator *
has higher precedence than the addition operator +
. Your task is to parse the expression and evaluate it correctly.
For example, the expression 3+5*2
should be evaluated as 3 + (5*2) = 13. Similarly, 2*3+4
should be evaluated as (2*3) + 4 = 10.
Note that the expression will only contain non-negative integers, the +
operator, and the *
operator, and no spaces.
The mathematical operations can be represented in LaTeX as follows:
- Addition: \(a+b\)
- Multiplication: \(a\times b\) or simply \(a*b\)
inputFormat
The input consists of a single line containing a string that represents the arithmetic expression.
You can assume that the expression is non-empty and only contains digits and the operators +
and *
.
outputFormat
Output a single integer which is the result of evaluating the expression using the usual operator precedence: multiplication before addition.
## sample3+5*2
13