AREX - Arithmetic Expressions
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.
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 digits
- Op ! Any of the following operators: ‘+’, ‘-’, ‘*’ , ‘/’
Observe that all the symbols (parenthesis, operators and numbers) are separated by spaces.
For each input case, the output will have a line with the real value obtained by evaluating its correspond-ing 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 not be divisions by 0, and the absolute value of the result will not be greater than 2000000.
( 3.00 + 4.50 )
( 5.00 - ( 2.50 * 3.00 ) )
( ( 7.00 / 3.00 ) + ( 4.00 - ( 3.00 * 7.00 ) ) )
No classical problem. Should be moved to tutorial.