fork(1) download
  1. char stack[401];
  2. int index=-1;
  3. void push(char value);
  4. main()
  5. {
  6. char arr[401];//remember this you always forget : 1 extra for '\0'
  7. char out[401];
  8.  
  9. int i,t=0,k=0;
  10. scanf("%d\n",&t);
  11.  
  12. while(t--)
  13. {
  14. k=0;
  15. i=0;
  16. scanf("%s",arr);
  17. while(arr[i]!='\0')
  18. {
  19. if(arr[i]=='('){push(arr[i]);}
  20. if(arr[i]=='*'){push(arr[i]);}
  21. if(arr[i]=='-'){push(arr[i]);}
  22. if(arr[i]=='+'){push(arr[i]);}
  23. if(arr[i]=='/'){push(arr[i]);}
  24. if(arr[i]=='^'){push(arr[i]);}
  25.  
  26. if((arr[i]>='a'&& arr[i]<='z')|| (arr[i]>='A'&& arr[i]<='Z') )
  27. {
  28. out[k]=arr[i];
  29. k++;
  30. }
  31.  
  32. if(arr[i] == ')')
  33. {
  34. while(stack[index]!='(')
  35. {
  36. out[k]= pop();
  37. k++;
  38. }
  39. pop();
  40. }
  41. i++;
  42. }
  43. if(index!=-1)
  44. {
  45. out[k]= pop();
  46. k++;
  47. }
  48. for(i=0;i<k;i++)
  49. {
  50. printf("%c",out[i]);
  51. }
  52. }
  53.  
  54. }
  55.  
  56. void push(char value)
  57. {
  58. index++;
  59. stack[index] = value;
  60.  
  61. }
  62.  
  63. pop()
  64. {
  65. index--;
  66. return(stack[index+1]);
  67. }
  68.  
Success #stdin #stdout 0s 2252KB
stdin
1
(a+b)*(c+d)*(e/f)
stdout
ab+cd+ef/*