fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int a, i;
  9. string s;
  10. stack <char> oper;
  11. stack <char> extra;
  12. cin>>a;
  13. while(a--) {
  14. cin>>s;
  15. for(i=0; i<s.size(); i++) {
  16. if(s[i]=='+' || s[i]=='-' || s[i]=='*' || s[i]=='/' || s[i]=='^' || s[i]=='%') oper.push(s[i]);
  17. else if(s[i]==')') {
  18. cout<<oper.top();
  19. oper.pop();
  20. }
  21. else if(s[i]=='(') extra.push(s[i]);
  22. else cout<<s[i];
  23. }
  24. cout<<endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 3436KB
stdin
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
stdout
abc*+
ab+zx+*
at+bac++cd+^*