fork(10) download
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <iostream>
  8. #include <map>
  9. #include <queue>
  10. #include <set>
  11. #include <sstream>
  12. #include <stack>
  13. #include <string>
  14. #include <vector>
  15.  
  16. #define EPS 1e-11
  17. #define inf ( 1LL << 31 ) - 1
  18. #define LL long long
  19.  
  20. #define abs(x) (((x)< 0) ? (-(x)) : (x))
  21. #define all(x) (x).begin(), (x).end()
  22. #define ms(x, a) memset((x), (a), sizeof(x))
  23.  
  24. #define mp make_pair
  25. #define pb push_back
  26. #define sz(k) (int)(k).size()
  27.  
  28. using namespace std;
  29.  
  30. typedef vector <int> vi;
  31. stack <char> charstack;
  32. int main ()
  33. {
  34. int total;
  35. cin >> total;
  36. while (total-- > 0)
  37. {
  38. string expn;
  39. cin >> expn;
  40. for (int i = 0; i < expn.length(); i++)
  41. {
  42. if (expn[i] >= 'a' && expn[i] <= 'z')
  43. {
  44. cout << expn[i];
  45. }
  46. else if (expn[i] == ')')
  47. {
  48. while (charstack.top() != '(')
  49. {
  50. cout << charstack.top();
  51. charstack.pop();
  52. }
  53. charstack.pop();
  54. }
  55. else
  56. {
  57. charstack.push (expn[i]);
  58. }
  59. }
  60. while (!charstack.empty())
  61. {
  62. cout << charstack.top();
  63. charstack.pop();
  64. }
  65. cout << endl;
  66. }
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.02s 2820KB
stdin
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
stdout
abc*+
ab+zx+*
at+bac++cd+^*