-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAE3.cpp
95 lines (90 loc) · 1.64 KB
/
AE3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<unordered_set>
#include<stack>
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
#include<cstring>
#include<algorithm>
#include<queue>
#include <stdio.h>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<climits>
#include<cmath>
#include<math.h>
#include<limits>
#define ll long long int
const ll N = 1e5+ 2,MOD = 1e9+7;
using namespace std;
int power(ll a,ll b) {
ll ans = 1;
while(b>0){
if(b%2){
ans=ans*a;
}
a=a*a;b>>=1;
}
return ans;
}
ll countSetBits(ll n) {
ll count = 0;
while (n)
{
count += n & 1;
n >>= 1;
}
return count;
}
ll gcd(ll a, string b){
ll res = 0;
for (int i = 0; i < b.length(); i++){
res = ((res * 10) + (b[i] - '0')) % a;
}
return __gcd(a,res);
}
void print(vector<ll> v,ll n){
for(ll i=0;i<n;i++){
cout<<v[i]<<' ';
}cout<<endl;
}
void solve(){
string s;cin>>s;
ll n = s.length();
stack<char> st;
st.push('$');
for(ll i=0;i<n;i++){
char t = st.top();
if((s[i] == 'A' && t == 'B') || (s[i] == 'B' && t == 'A') || (s[i] == 'C' && t == 'D') || (s[i] == 'D' && t == 'C')){
st.pop();
}else{
st.push(s[i]);
}
}
if(st.size() == 1){
cout<<" "<<endl;
return;
}
string t = "";
while(st.size()>1){
t += st.top();
st.pop();
}
reverse(t.begin(),t.end());
cout<<t<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}