fork download
  1. /*
  2. ==> Don't stop when you're tired, stop when you're done.
  3. ==> From the river to the sea, Palestine will be free.
  4. --> @author: MIDORIYA_
  5. */
  6. //*==============================================================
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. typedef long long ll;
  10. typedef double db;
  11. typedef long double ld;
  12. typedef pair<int, int> pii;
  13. typedef pair<ll, ll> pll;
  14. typedef vector<int> vi;
  15. typedef vector<ll> vll;
  16. typedef vector<db> vd;
  17. typedef vector<ld> vld;
  18. typedef vector<bool> vb;
  19. typedef vector<vector<ll>> vvl;
  20. typedef vector<vector<int>> vvi;
  21. typedef vector<pii> vii;
  22. typedef set<int> si;
  23. typedef set<ll> sl;
  24. #define pb push_back
  25. #define all(x) x.begin(), x.end()
  26. #define rall(x) x.rbegin(), x.rend()
  27. #define endl "\n"
  28. const int MOD = 998244353, mod = 1e9 + 7, maxA = 1e5 + 5;
  29. #define time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs";
  30. //*===================>>>FastIO - FileIO<<<=========
  31. void fastIO()
  32. {
  33. ios_base::sync_with_stdio(false);
  34. cin.tie(nullptr);
  35. cout.tie(nullptr);
  36. }
  37. void fileIO()
  38. {
  39. #ifndef ONLINE_JUDGE
  40. freopen("in.txt", "r", stdin);
  41. freopen("out.txt", "w", stdout);
  42. #endif
  43. }
  44. //*===================>>>ONE-FOR-ALL<<<=============
  45. void OneForAll()
  46. {
  47. int n;
  48. cin >> n;
  49. string str, res = "";
  50. cin >> str;
  51.  
  52. stack<char> st;
  53.  
  54. for (int i = 0; i < str.size(); i++)
  55. {
  56. if(st.empty())
  57. {
  58. st.push(str[i]);
  59. }
  60. else
  61. {
  62. if(str[i] == st.top())
  63. {
  64. res += str[i];
  65. st.pop();
  66. }
  67. }
  68. }
  69.  
  70. cout << res << endl;
  71. }
  72.  
  73. int main()
  74. {
  75. fastIO();
  76. fileIO();
  77.  
  78. ll tc = 1, t = 1;
  79. cin >> t;
  80. while (t--)
  81. {
  82. // cout << "Case " << tc++ << ": ";
  83. OneForAll();
  84. }
  85. time;
  86. return 0;
  87. }
Success #stdin #stdout #stderr 0.01s 5328KB
stdin
Standard input is empty
stdout

	
stderr
Time Taken: 0.006298 Secs