ECOO AT GRAMERCY 1999

Just Kill Me Now

INPUT FILE: kill.in
OUTPUT FILE: kill.out

Given an algebraic expression using the operator set {+ - * / ^ ( ) { }} format the expression according to the following rules:

  1. Insert a space around these operators: + - *
  2. Print the exponent of the ^ operator a line higher than the remainder of the expression
  3. Print the numerator a line higher, and the denominator a line lower for the / operator. Print a dividing line (----) at the level of the remainder of the expression.
  4. Expressions in brackets should obviously be grouped first - if round brackets ( ) occur, print them out. If curly brackets { } occur, do NOT print them out.
  5. Numerators and denominators for the / operator should be centered on top and bottom. Round positions of operands to the right.
  6. Expressions should be centred vertically according to their "centre of mass," which is defined as: dividing line for /, bottom-most operator for + - * ^. For expressions inside brackets the centre of mass is the geometrical centre Round the position of operands downwards.

You may implement only rules 1 through 4 for partial credit.

INPUT
On each line of the input file is an expression to be formatted.

OUTPUT
For each expression in the input file, first echo the expression and then output the expression as it appears when formatted according to the above rules. Leave a blank line between expressions.

Sample Input File

(1+2)/3+4
{1+20}/3+4
1^2^3+5
(1^2)^3+5
(1^2^3)+5
1/2/3+4

Output for Sample Input (Partially formatted on left, fully formatted on right)

(1+2)/3+4
(1 + 2)               (1 + 2)
------- + 4           ------- + 4
3                        3

{1+20}/3+4
1 + 20                1 + 20
------ + 4            ------ + 4
3                        3

1^2^3+5
  3                     3
 2                     2 
1   + 5               1   + 5

(1^2)^3+5
    3                     3
( 2)                  ( 2)  + 5
(1 )  + 5             (1 )


(1^2^3)+5
(  3)                 (  3)
( 2 )                 ( 2 ) + 5
(1  ) + 5             (1  )


1/2/3+4
1                     1
-                     -
2                     2
-                     - + 4
3 + 4                 3
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.