AREX - Arithmetic Expressions

no tags 

Let’s start with an easy problem. Given a set of arithmetic expressions, the goal of this problem is to obtain their evaluation values.

For instance, given the expression (3.00 + 4.50) its evaluation value will be the real value 7.50.

Given a set of N arithmetic expressions, each of the form Real or (Expression Op Expression) with Op one of the following arithmetic operators: +, -, *, /.

The goal is to obtain the evaluation value of each arithmetic expression.

Input

The first line contains a natural number N that indicates the number of arithmetic expressions to evaluate, followed by the arithmetic expressions, each one in one of the following lines.

The following lines contain, each line, an arithmetic expression of real numbers of the form:

  • Expression ! Real
  • Expression ! ‘( Expression Op Expression )’
  • Real ! Real number with two decimal places
  • Op ! Any of the following operators: ‘+’, ‘-’, ‘*’, ‘/’

Observe that all the symbols (parenthesis, operators and numbers) are separated by spaces.

Output

For each input case, the output will have a line with the real value obtained by evaluating its corresponding arithmetic expression. The real number will have two decimal digits, rounding to the nearest real value, without using floating point representation. For example: 0.005 is rounded to 0.01; 0.00499999 is rounded to 0.00; -0.005 is rounded to -0.01; and -0.00499999 is rounded and represented as -0.00. The evaluation value of an arithmetic expression will be a real value calculated as follows:

  • Evaluation of Real = Real
  • Evaluation of ( Expression1 Op Expression2 ) = Evaluation of Expression1 Op Evaluation of Expression2

There will be no divisions by 0, and the absolute value of the result will not be greater than 2000000.

Example

Input:
3
( 3.00 + 4.50 )
( 5.00 - ( 2.50 * 3.00 ) )
( ( 7.00 / 3.00 ) + ( 4.00 - ( 3.00 * 7.00 ) ) )

Output:
7.50
-2.50
-14.67

hide comments
Mitch Schwartz: 2014-10-12 18:20:08

Moved.

numerix: 2014-10-12 16:11:34

No classical problem. Should be moved to tutorial.


Added by:Alim
Date:2014-10-11
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:UVA