#K35357. Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
You are given an arithmetic expression that contains non-negative integers along with two operators: addition (+
) and multiplication (*
). In this expression, multiplication has a higher precedence than addition (i.e., multiplication is performed before addition). There are no parentheses in the expression.
Your task is to calculate and output the value of the expression following the standard operator precedence. For example, given the expression 2+3*4
, the result is computed as 2 + (3*4) = 14.
Note: The input is provided through the standard input (stdin) and the output must be printed to the standard output (stdout).
inputFormat
The input consists of a single line containing a string expression
which represents the arithmetic expression. The expression includes non-negative integers and the operators +
and *
without any spaces.
Example Input: 2+3*4
outputFormat
Output a single integer, which is the result of evaluating the expression under the precedence rule (multiplication before addition).
Example Output: 14
2+3*4
14