fork(3) download
  1. # your code goes here
  2. # your code goes here
  3. for _ in range(int(input())):
  4. oper = []
  5. st = input()
  6. opList = '(^*/+-'
  7. top = ""
  8. for s in st:
  9. if(s.isalpha()):
  10. print(s, end="")
  11. if("+-*/^(".find(s) != -1):
  12. if(len(oper)!= 0):
  13. top = oper[-1]
  14. while(((opList.find(top)<opList.find(s)) or (s=="*" and top=="/") or (s=="/" and top=="*") or (s=="+" and top=="-") or (s=="-" and top=="+")) and (top!="(")):
  15. print(oper.pop(), end="")
  16. oper.append(s)
  17. if(s == "("):
  18. oper.append("(")
  19. if(s == ")"):
  20. while(oper[-1] != "("):
  21. print(oper.pop(), end="")
  22. if(oper[-1] == "("):
  23. oper.pop()
  24. while(len(oper) != 0):
  25. if(oper[-1] == "("):
  26. oper.pop()
  27. else:
  28. print(oper.pop(), end="")
  29. print("")
Success #stdin #stdout 0.01s 27712KB
stdin
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
stdout
abc*+
ab+zx+*
at+bac+cd+^+*