<PREV Problem:
NEXT>
Solved by 110 users: ...
UserDateAttemptTimeCMSC
sb3ar24 apr 2008Ruby1000.9863 
asp12 jul 2007C++1000.93145 
daniel.ugra13 jan 2007Ruby306.09147 
Lukasz16a09 jun 2008C++200.77166 
asp12 jul 2007C++400.13170 
daniel.ugra13 jan 2007Ruby103.12184 
lim0n30 mar 2011C200.06188 
monsoon18 may 2007C++100.07188 
Xameleon04 dec 2006C++300.07204 
vi00209 dec 2007C++500.09250 
cyberian26 apr 2007C++1100.33252 
jeeva28 may 2007C++100.17253 
Languages
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

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 210ms

SW soft NIX
ID = 34.204.191.0