-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabbb.cpp
59 lines (46 loc) · 840 Bytes
/
abbb.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
/**
*
* @Author : Vinay Kushwaha (iamvinayvk)
*
* @DateTime : 10/18/2020 12:24:08 PM
*
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define w(t) int t;cin>>t;while(t--)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define vi vector<int>
#define vll vector<long long>
#define FOR(start,end,increment) for(ll i=start;i<end;i+=increment)
ll gcd(ll a, ll b)
{
if(a==0)
return b;
return gcd(b%a,a);
}
int main(){
fast
w(t)
{
string s;
cin>>s;
stack<char> st;
st.push(s[0]);
for(int i=1;i<s.length();i++)
{
if(s[i]=='B'&&!st.empty())
{
st.pop();
continue;
}
st.push(s[i]);
}
cout<<st.size()<<"\n";
}
return 0;
}