Codeforces 1424C. ABBB Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- string s;
- stack<char>st;
- cin>>s;
- for(int i=0; i<s.size(); i++)
- {
- if(!st.empty())
- {
- if(s[i]=='B')
- st.pop();
- else
- st.push(i);
- }
- else
- st.push(i);
- }
- cout<<st.size()<<endl;
- }
- }
No comments