10838 - EEDS Spaceship calculator   

Description


Houston, we have had a problem!  Our spaceship accindentally flew into a black hole.  Time and space thus all distorrrrrrrt.  Believe or not, even the priority of our familiar arithmetic operators are changed

The priority of arithmetic operators in this black hole is as follows:

  -   the highest
  *    /    middle
  +   the lowest


Other rules are the same as integer arithmetics on Earth.

Let us take 7/9-8+5*7*1 for example.  What we are familair with on Earth is:

7/9-8+5*7*1
= ((7/9)-8)+((5*7)*1)
= (0-8)+(35)
= 27

However, in this black hole we have:

7/9-8+5*7*1
= (7/(9-8))+((5*7)*1)
= 42

Very strange, right?  Even worse, the navigation calculator of our spaceship stops working because of this difference, and thus we cannot find the right path back to Earth now.

Fortunately, some students at NTHU are helping us reprogramming the navigation calculator.  They arrrrre our future!! 

 

Input

There are multple lines, each being an arithemetic expression.

Each expression can contain

  1. Several single-digit, integer operands, 0, 1, .., 9  (i.e., each operand is a char)
  2. Several arrithmetic operators, + - * /
  3. A few parentheses

An expression contains no space characters in between operands, operators, and delimiters. 

Each expression ends up with a newline character.

Output

For each expression, please perform the following four lines

  1. Output the expression
  2. Output "= " followed by the parenthesized expression based on the priority in the black hole
  3. Output "= " followed by the result
  4. Five dash characters, "-----", as a separator

Please note that

  1. Output "= NaN" (i.e., Not a Number) for an expression that causes division by zero
  2. Please adopt integer division.  For exmape, 5/6=0, 1/(2-4)=0
  3. Please output the parenthesized expression without the outermost pair of parenthesis, which is redundant, e.g., the red parenthese in the folllowing example.
    7/9-8+5*7*1
    = ((7/(9-8))+((5*7)*1))
    = 42

Sample Input  Download

Sample Output  Download

Tags




Discuss