fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int t;
  8. string str;
  9.  
  10. cin>>t;
  11.  
  12. while(t--){
  13. int a=0, b=0;
  14. cin>>str;
  15.  
  16. for(int i=0;i<str.size();i++){
  17. if(str[i]=='a')
  18. a++;
  19. else
  20. b++;
  21. }
  22.  
  23. cout<<min(a,b)<<"\n";
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5324KB
stdin
3
ab
bb
baaba
stdout
1
0
2