-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathC.cpp
More file actions
35 lines (34 loc) · 635 Bytes
/
C.cpp
File metadata and controls
35 lines (34 loc) · 635 Bytes
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
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1e18;
void read_file(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
int main(){
read_file();
ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
string s;
cin >> s;
stack<char> st;
for(int i = 0 ; i < (int)s.length() ; ++i){
if(!st.empty() && st.top() == 'A' && s[i] == 'B'){
st.pop();
continue;
}
else if(!st.empty() && st.top() == 'B' && s[i] == 'B'){
st.pop();
continue;
}
st.push(s[i]);
}
cout << (int)st.size() << '\n';
}
return 0;
}