Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- string s;
- cin>>s;
- set<pair<int, char>> x, y;
- for(int i=0; i<s.size(); i++)
- {
- if(s[i] == 'b')
- {
- if(x.size()) x.erase(--x.end());
- continue;
- }
- if(s[i] == 'B')
- {
- if(y.size()) y.erase(--y.end());
- continue;
- }
- if(s[i]>='a' && s[i]<='z') x.insert({i, s[i]});
- if(s[i]>='A' && s[i]<='Z') y.insert({i, s[i]});
- }
- set<pair<int, char>> z;
- for(auto e: x) z.insert(e);
- for(auto e: y) z.insert(e);
- for(auto [e, c]: z)
- cout<<c;
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment