ONP - Transform the Expression
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).
Input
t [the number of expressions <= 100] expression [length <= 400] [other expressions]
Text grouped in [ ] does not appear in the input file.
Output
The expressions in RPN form, one per line.
Example
Input: 3 (a+(b*c)) ((a+b)*(z+x)) ((a+t)*((b+(a+c))^(c+d))) Output: abc*+ ab+zx+* at+bac++cd+^*
hide comments
iamareebjamal:
2016-01-13 11:47:36
Runs perfectly on ideone.com
|
|
cherag_0001:
2016-01-04 08:32:29
whooo hoo !! 2nd try ..// in the first try just an "endl" missing :P |
|
skrishna99:
2015-12-31 10:41:16
I got RTE(NZec) I tried all known options to me , finally identified that I have not pushed "-" to stack . Pretty easy problem using stacks.
|
|
ashu14:
2015-12-27 15:51:29
@yeahboy this type is not allowed.. As it can have multiple rpn forms possible! |
|
motasem mohammad:
2015-12-25 14:10:18
taught me how to use stack function , a good problem |
|
aakash_s:
2015-12-17 18:36:07
Take care of the case a+b without any brackets ...caused me several wrong answers
|
|
Timmy Jose:
2015-12-13 21:25:34
Nice question - excellent motivation to revise old college stuff! :-) |
|
MAYANK NARULA:
2015-12-09 07:05:06
@ yeahboy ... My answer for that is abc*-w-lde-fg+*-h+ijk-*p/^-
|
|
Mayur Aggarwal:
2015-10-21 14:25:15
My code is giving correct answer on ideone but couldn't able to nail down the issue/bug for which SPOJ is giving wrong answer. few checks are given below please advise if any see any issue:
|
|
Michael:
2015-10-12 21:04:55
In my case it's:
|
Added by: | mima |
Date: | 2004-05-01 |
Time limit: | 5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 VB.NET |
Resource: | - |