fork download
  1. #include<stdio.h>
  2. char string[405],stack1[405],stack2[405];
  3. int main()
  4. {
  5. int n,j,i,t1=-1,t2=-1;
  6. scanf("%d",&n);
  7. for(i=0;i<n;i++)
  8. {
  9. scanf("%s",&string);
  10. for(j=0;string[j]!='\0';j++)
  11. {
  12. if((string[j]=='(')||(string[j]=='+')||(string[j]=='-')||(string[j]=='*')||(string[j]=='/')|| (string[j]=='^'))
  13. stack1[++t1]=string[j];
  14. else if(string[j]==')')
  15. while(1)
  16. {
  17. if(stack1[t1]=='(')
  18. {
  19. stack1[t1--]=NULL;
  20. break;
  21. }
  22. stack2[++t2]=stack1[t1];
  23. stack1[t1--]=NULL;
  24. }
  25. else
  26. stack2[++t2]=string[j];
  27. }
  28. printf("%s",stack2);
  29. printf("\n");
  30. for(j=0;stack2[j]!='\0';j++)
  31. stack2[j]=NULL;
  32. for(j=0;stack1[j]!='\0';j++)
  33. stack1[j]=NULL;
  34. t1=-1;t2=-1;j=0;
  35. }
  36. }
Success #stdin #stdout 0.02s 2684KB
stdin
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
stdout
abc*+
ab+zx+*
at+bac++cd+^*