fork download
  1. import re
  2. q=re.sub
  3. g=lambda m:'--'+m.group()[1:]
  4. h=lambda m:'/(1/'+m.group()[1:]+')'
  5. i=lambda m:'0/'+m.group()[:-2]
  6. print(q(r'\*[^\(\)]+',h,q(r'[^\(\)]\*0',i,q(r'\+[^\(\)]+',g,q(r'\*\([^\)]+\)',h,q(r'\([^\)]+\)\*0',i,q(r'\+\([^\)]+\)',g,input().replace(' ',''))))))))
Success #stdin #stdout 0.02s 9992KB
stdin
1 + (x * 4) - (512 * 3)
stdout
1--(x/(1/4))-(512/(1/3))