Sphere Online Judge

SPOJ Problem Set (classical)

4. Transform the Expression

Problem code: ONP

Transform the algebraic expression with brackets into RPN form (Reverse Polish Notation). Two-argument operators: +, -, *, /, ^ (priority from the lowest to the highest), brackets ( ). Operands: only letters: a,b,...,z. Assume that there is only one RPN form (no expressions like a*b*c).


t [the number of expressions <= 100]
expression [length <= 400]
[other expressions]

Text grouped in [ ] does not appear in the input file.


The expressions in RPN form, one per line.




Added by:Micha≥ Ma≥afiejski
Time limit:5s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-09-29 20:13:59 Hot-Shot
recursion is my sole mate
2014-08-30 14:31:36 saikat
0.00 1.6M in C.. The best code..
2014-08-22 08:53:47 Gaurav Ahirwar
Xtremely Simple logic! ..just give it a try! :)
2014-08-21 14:57:49 Emanuele Paolini
I think that for clarification the expression a-b+c-d should be added to the examples. Priority of operators is not shown in any example.
2014-01-28 10:02:35 Shatha Abu Hashem
Ugh .. I Just cannot find the algorithm .. it drives me crazy
2013-12-25 17:54:00 Bowen
"+, -, *, /, ^ (priority from the lowest to the highest)"
does - have higher precedence than + or are they the same? also with * and /?
2013-12-12 07:55:21 Duan Yichao
Write some more expressions yourself and try.
2013-08-28 19:54:59 Mayank Raj
Actually everything is bracketed...I coded to look only for the braces!!
2013-08-06 08:24:01 Franz Matejka
Suggestion: Add to problem statement that the algorithm just needs to work with fully bracketed expressions.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.