#C14144. Infix Expression Conversion and Evaluation

    ID: 43761 Type: Default 1000ms 256MiB

Infix Expression Conversion and Evaluation

Infix Expression Conversion and Evaluation

This problem requires you to convert infix arithmetic expressions to postfix notation (Reverse Polish Notation) and then evaluate them. The expressions may include integers, parentheses, and the operators +, -, *, and / with standard operator precedence. The division operator (/) should perform floating-point division. Use a stack-based algorithm for the conversion and evaluation (\(\text{infix to postfix conversion}\) in \(\LaTeX\) format). Your solution should read multiple expressions from standard input and output the evaluated result for each expression on a separate line.

inputFormat

The first line contains an integer n, the number of expressions. Each of the following n lines contains an infix expression with tokens separated by a single space.

outputFormat

Output n lines. Each line should contain the evaluated result of the corresponding expression. If the result is an integer, output it without a decimal fraction; otherwise, output the floating-point result.

## sample
2
3 + 4 * 2 / ( 1 - 5 )
10 + 2 * 6
1.0

22

</p>