Solved by 110 users: ...
UserDateAttemptTimeCMSC
sb3ar`24 apr 2008`Ruby1000.9863
asp`12 jul 2007`C++1000.93145
daniel.ugra`13 jan 2007`Ruby306.09147
Lukasz16a`09 jun 2008`C++200.77166
asp`12 jul 2007`C++400.13170
daniel.ugra`13 jan 2007`Ruby103.12184
lim0n`30 mar 2011`C200.06188
monsoon`18 may 2007`C++100.07188
Xameleon`04 dec 2006`C++300.07204
vi002`09 dec 2007`C++500.09250
cyberian`26 apr 2007`C++1100.33252
jeeva`28 may 2007`C++100.17253
 C++ 76 C 14 Java 8 Kylix 6 Ruby 4 FPC 3 Scheme 1
` >  >  >  >  >  >  >  >  >  > `

## Infix to postfix form

Time limit = 3 second(s)

Grammar of infix notation is the following:

``` S ::= (S ('+' | '-'))? B
B ::= (B ('*' | '/'))? A
A ::= '-'? NUMBER
| '-'? '(' S ')'
NUMBER ::=  nonnegative integer number less then 109 ;
```

Whitespace characters can be placed between any two elements ('\t', ' ', '\n').

All binary operands are left-associate.

Input. Several lines with infix form of arithmetic expression. It's length is less then 400000.

Output. Postfix expression. Tokens should be separated by space. Unary minus should be represented by letter 'n'.

 Input#1```-1-2-3 ``` Output#1```1 n 2 - 3 - ```
 Input#2```-1-(2-3) ``` Output#2```1 n 2 3 - - ```
 Input#3```1 + (3*4) *5 / 6/7 ``` Output#3```1 3 4 * 5 * 6 / 7 / + ```
 Input#4```100 + 1 - 1 / 34 + 1*2*3*4 ``` Output#4```100 1 + 1 34 / - 1 2 * 3 * 4 * + ```
 Input#5```1--2*4 ``` Output#5```1 2 n 4 * - ```

Author:
Classic problem. Tests and description by Artem Voroztsov

 © acm.mipt DevGroupThe page was generated in 190ms