#C14430. Evaluate Expression
Evaluate Expression
Evaluate Expression
You are given a mathematical expression as a string consisting only of non-negative integers and the operators '+' and '*'. The expression does not contain any spaces. In this expression, multiplication has higher precedence than addition.
Your task is to evaluate the expression correctly without using any built-in evaluation functions. For example, given the expression 3+5*2
, you should first calculate 5*2 = 10
and then add 3
to obtain 13
.
In mathematical terms, if the expression is given by:
$$ E = a_1 + a_2* a_3 + a_4* a_5 * a_6 + \cdots, $$you must compute the result by applying multiplication before addition.
inputFormat
The input consists of a single line containing the expression. The expression includes only digits (0-9) and the operators '+' and '*'.
Example: 3+5*2
outputFormat
Output a single integer which is the evaluated result of the expression.
Example: For the input 3+5*2
, the output should be 13
.
3+5*2
13