#C12395. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
Given a mathematical expression as a string, your task is to evaluate its value and output the result as a floating point number. The expression may contain integers, floating-point numbers, and the operators \( + \), \( - \), \( \times \) (or \( * \)), \( \div \) (or \( / \)), as well as parentheses \( ( \) and \( ) \). Operator precedence must be correctly observed: multiplication and division have higher precedence than addition and subtraction, and parentheses override the default precedence.
Note: You are not allowed to use the built-in eval
function or similar utilities.
Examples:
- Input:
3 + 5
→ Output:8.0
- Input:
10 + 2 * 6
→ Output:22.0
- Input:
(10 + 2) * 6
→ Output:72.0
inputFormat
The input consists of a single line containing a valid mathematical expression.
outputFormat
Output a single floating point number which is the result of evaluating the expression. The result should be printed on stdout.
## sample3 + 5
8.0