Codeforces 1424C. ABBB Solution

 Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh 

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. string s;
  10. stack<char>st;
  11. cin>>s;
  12. for(int i=0; i<s.size(); i++)
  13. {
  14. if(!st.empty())
  15. {
  16. if(s[i]=='B')
  17. st.pop();
  18. else
  19. st.push(i);
  20. }
  21. else
  22. st.push(i);
  23. }
  24. cout<<st.size()<<endl;
  25.  
  26. }
  27. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.