fork download
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int t;
  9. cin>>t;
  10.  
  11. while(t--)
  12. {
  13. string a;
  14. cin>>a;
  15.  
  16. stack<int> smalls, capitals;
  17. unordered_map<int, bool> deleted;
  18.  
  19. for(int i{}; i<a.size(); i++)
  20. {
  21. if(a[i] == 'b')
  22. {
  23. deleted[i] = true;
  24.  
  25. if(!smalls.empty())
  26. {
  27. deleted[smalls.top()] = true;
  28. smalls.pop();
  29. }
  30. }
  31.  
  32. else if(a[i] == 'B')
  33. {
  34. deleted[i] = true;
  35.  
  36. if(!capitals.empty())
  37. {
  38. deleted[capitals.top()] = true;
  39. capitals.pop();
  40. }
  41. }
  42.  
  43. else if('a' <= a[i] && a[i] <= 'z')
  44. {
  45. smalls.push(i);
  46. }
  47.  
  48. else if('A' <= a[i] && a[i] <= 'Z')
  49. {
  50. capitals.push(i);
  51. }
  52. }
  53.  
  54. for(int i{}; i < a.size(); i++)
  55. {
  56. if(!deleted[i])
  57. cout<<a[i];
  58. }
  59.  
  60. cout<<endl;
  61. }
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 5312KB
stdin
12
ARaBbbitBaby
YetAnotherBrokenKeyboard
Bubble
Improbable
abbreviable
BbBB
BusyasaBeeinaBedofBloomingBlossoms
CoDEBARbIES
codeforces
bobebobbes
b
TheBBlackbboard
stdout
ity
YetnotherrokenKeoard
le
Imprle
revile

usyasaeeinaedofloominglossoms
CDARIES
codeforces
es

helaoard