postfix to infix

Submit

Your name:
File:
Open code-statistics:

Language is selected by the extension of the file. See the list of supported languages to know the extension of your language.

Problem

Convert from postfix (reverse polish notation) to minimally parenthesized infix notation. * and / are higher precedence than + and -. * and + are associative while - and / are not.

abc+- -> a-(b+c)
abc++ -> a+b+c, not a+(b+c) because associativity.
ab+c* -> (a+b)*c
ab*c+ -> a*b+c, parenthesis not needed due to higher precedence.

Options

exec is denied

now post-mortem time, all source codes will be revealed

Sample input:_

abc+-
abc++
ab+c*
ab*c+

Sample output:

a-(b+c)
a+b+c
(a+b)*c
a*b+c

Sample input:_

kr/vgop*d*q/lzn*+hy/w*-j-x+ia*+c*s+*m//b/*u/e-f-/
ug*i*d*b/h*zel*c-*w+q*av/-/f*
an/e/dyb/p*ks/w/mvj/i//t*/**qg/-*c/r*
alfb*r*h*n*q/so/vc*t*--*x*d+i/j//
imyq*o*g/w/r/k-/un*+bxf/lae/-j/**+/t*d*ch*-
ktx/ej/a*d/r*m*i-n*f*qhvc*lo+*-*g*-/us*p*+/
ftvj/cy*glmzi*qd*x***o/-/n-p-b-/e/**k+uw*+ha*-/
in*p*v/j/x*ub*qrht/a/lcef/++k-/z//-*yo/+ds/-/g-m-
dzf/r/pl*emiw/h*k*xc/g+/*-o+n-/*j/*b/
bp/tva/y*ej*m/sz/r-hn-+-/u*i/*d+*
ad/v*l*ey/x/qz/s-*p/j//
ba/vwg*i/q*j/lc-*dym/f*/o+p+s*-//x/r-

Sample output:

k/r/(v*g/(o*p*d/q*((l+z*n-h/y*w-j+x+i*a)*c+s)/m)/b/u-e-f)
u*g*i*d/b*h/((z*(e*l-c)+w)*q-a/v)*f
a/n/e*(d*y/b*p*k/s/w/(m/(v/j/i)*t)-q/g)/c*r
a/((l*(f*b*r*h*n/q-(s/o-v*c*t))*x+d)/i/j)
i/(m/(y*q*o/g/w/r-k)+u*n+b*x/f*(l-a/e)/j)*t*d-c*h
k/(t/x/((e/j*a/d*r*m-i)*n*f-q*(h-v*c*(l+o))*g)+u*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/(w*(n*g*d*v/o/q*(r-h/s/f*z)+t*m))/e)
w/n*(v/(q/a/f/j+x*t*b*(y/l/p*k-d+u)/e/m*g)/(o*r/i/c)-s)/h-z
j/((z*c*p*i*(o/x-(h*g/t-a/e/b*(n-y)))*l*k+s+v)*d*w)
y*u*v/(h*b*e/i*j)*f*k*g
u*o*(r/y*e*(p*s/h*b-j)*d+l/f)-i

Ranking

Ruby _

RankUserSizeTimeDateStatistics
1kinaba1010.26092008/01/19 12:26:130B / 36B / 62B
2flagitious1020.13082008/01/12 13:24:160B / 39B / 58B
3ksk1210.29902008/01/22 01:08:170B / 48B / 67B
4shinh1330.29412008/01/18 09:36:110B / 51B / 75B
5yowa1490.15222008/01/21 09:33:540B / 54B / 89B
6xdigit2480.22622008/01/10 19:31:120B / 97B / 133B
7kinaba990.22672008/01/22 12:43:290B / 38B / 58B

Perl _

RankUserSizeTimeDateStatistics
1ySas1190.19042008/01/21 18:44:510B / 36B / 82B

Python _

RankUserSizeTimeDateStatistics
1Mark Byers1640.22082008/01/20 23:31:250B / 59B / 83B
2kt3k2750.10992008/01/09 13:42:200B / 125B / 123B

Common LISP _

RankUserSizeTimeDateStatistics
1kozima2760.96182008/01/22 11:59:060B / 131B / 130B

JavaScript _

RankUserSizeTimeDateStatistics
1nn1280.09172008/12/28 22:52:030B / 61B / 66B
2murky-satyr1360.17472008/05/24 01:52:100B / 60B / 74B

C _

RankUserSizeTimeDateStatistics
1letter1490.05982008/01/22 04:07:090B / 71B / 78B
2hinoe1540.04712008/01/22 02:34:490B / 75B / 79B
3kinaba1580.08092008/01/20 00:13:560B / 76B / 81B
4funnything1770.09022008/01/22 06:43:330B / 89B / 87B
5ozy4dm1860.06882008/01/22 10:01:390B / 92B / 94B
651b2160.03142008/01/14 17:26:290B / 107B / 105B

OCaml _

RankUserSizeTimeDateStatistics
1ksk2160.16762009/10/11 23:45:370B / 116B / 84B
2xsd2390.17632009/10/11 18:01:390B / 145B / 71B

Haskell _

RankUserSizeTimeDateStatistics
1notogawa2170.02812008/01/12 22:41:140B / ?B / ?B
2int-e1850.03432014/12/10 01:45:370B / 83B / 96B

AWK _

RankUserSizeTimeDateStatistics
1nn1160.07572008/12/28 22:40:510B / 55B / 57B

sed _

RankUserSizeTimeDateStatistics
1tails1440.04772013/05/10 07:04:020B / 16B / 122B

Postscript _

RankUserSizeTimeDateStatistics
1yshl(bin)1590.53542008/01/22 00:04:0860B / 61B / 37B
2ySas1610.56122008/01/21 19:36:2562B / 50B / 47B
3yshl1880.61272008/01/19 03:36:4377B / 72B / 37B
4yshl(not bin)2660.53202008/01/22 00:03:500B / 183B / 41B
5yshl(bin)1380.56752008/01/27 16:41:5155B / 51B / 31B
6yshl(not bin)2140.53032008/01/27 16:41:410B / 141B / 42B

GolfScript _

RankUserSizeTimeDateStatistics
1irori600.45762008/01/20 10:42:090B / 16B / 44B
2flagitious680.48042008/01/09 23:38:200B / 14B / 54B
3flagitious(sym)790.58612008/01/09 23:47:150B / 0B / 77B

Unlambda _

RankUserSizeTimeDateStatistics
1irori9210.09722008/01/14 21:20:550B / 428B / 491B

z80 _

RankUserSizeTimeDateStatistics
1kodera560.33052008/01/11 20:12:4930B / 12B / 12B
2ySas680.74542008/01/21 15:50:2932B / 11B / 21B
3kochi1990.09342008/01/22 03:11:57128B / 20B / 40B
4kodera510.29222008/01/22 22:29:1623B / 10B / 15B

goruby _

RankUserSizeTimeDateStatistics
1flagitious(sym)1620.23712008/01/10 01:30:210B / 0B / 158B

Groovy _

RankUserSizeTimeDateStatistics
1murky-satyr1233.84662009/12/16 08:25:240B / 61B / 57B

Language Ranking_

RankLangUserSizeScore
1z80kodera5110000
2GolfScriptirori608500
3Rubykinaba995151
4AWKnn1164396
5PerlySas1194285
6Groovymurky-satyr1234146
7JavaScriptnn1283984
8Postscriptyshl(bin)1383695
9sedtails1443541
10Cletter1493422
11gorubyflagitious(sym)1623148
12PythonMark Byers1643109
13Haskellint-e1852756
14OCamlksk2162361
15Common LISPkozima2761847
16Unlambdairori921553

return top