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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.