#C3796. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are required to evaluate a mathematical expression consisting of integers, the binary operators +
, -
, *
, and /
, and parentheses. The expression obeys the standard operator precedence rules: multiplication and division have higher precedence than addition and subtraction. Parentheses ( ) can be used to override the default precedence.
In mathematical terms, if you have an expression of the form \[ E = a + b * c - d / e \] then the multiplication and division are performed before the addition and subtraction.
Your program must read the expression from the standard input and output the evaluated result to the standard output. If the result is an integer, output it without a decimal point, otherwise output the float value.
inputFormat
The input consists of a single line containing a valid mathematical expression. The expression may contain spaces, digits, the operators +
, -
, *
, /
, and parentheses (
and )
.
outputFormat
Output a single line containing the evaluated result of the expression. If the result is a whole number, do not print a decimal point.
## sample3 + 5
8