This is problem 4 of the Victor's Various Adventures
problem set.
Victor is writing a math contest, and easily solves all of the problems. However, he wants to test you with a very easy problem that was on the contest. To make it even easier for you, he has decided that you can write a program to solve the problem. The problem is as follows:
We define an expression as something that can be evaluated to a real number, or is directly one (meaning that it is already a number). An expression is always surrounded by parenthesis
()
.Two expressions can be combined to form a nested expression with an operator.
For example, the number
( 11 )
is a direct expression, and the nested expression( ( 11 ) + ( ( 49 ) + ( 33 ) ) )
can be evaluated to a real number if the+
operator is defined.We will define 3 basic operations:
Operator Operation !
If the left input is larger than the right, apply addition. Otherwise, apply subtraction. @
If the left input is larger than the right, apply subtraction. Otherwise, apply addition. $
Compute the result with the following formula: , where is the left input, and is the right input.
To prove your brilliance to Victor, can you solve the problem?
Input Specification
On the first and only line, there will be a valid expression, as specified above. The line will end with the =
character.
It is guaranteed that all of the numbers in the input are non-negative.
Output Specification
Output the evaluated result to one decimal place.
Sample Input
( ( 4 ) ! ( 11.45 ) ) =
Sample Output
-7.4
Explanation for Sample Input 1
In this sample, since , we apply subtraction.
( ( 4 ) ! ( 11.45 ) )
= =
Sample Input 2
( ( ( 1.2 ) $ ( 5531 ) ) @ ( ( ( 11 ) ! ( 0.1 ) ) $ ( 44.01 ) ) ) =
Sample Output 2
5485.6
Comments