Help me in solving STC14 problem

My issue

My code

// Update the code below to solve this problem

#include <bits/stdc++.h>
using namespace std;

   
    


int main() 
{
	int t;
    cin >> t;
	
	while(t--)
	{
	    string s;
	    cin >> s;
	    
	int flip0 = 0, flip1 = 0, flag0 = 0, flag1 = 1;

    //converting to string starting with 0
    for (int i = 0; i < s.length(); i++) {
        if (flag0 != s[i] - 'a')
            flip0++;
        flag0 = 1 - flag0;
    }

    //converting to string starting with 1
    for (int i = 0; i < s.length(); i++) {
        if (flag1 != s[i] - 'a')
            flip1++;
        flag1 = 1 - flag1;
    }
 
	    
	}
}
        

Learning course: Solve Programming problems using C++
Problem Link: CodeChef: Practical coding for everyone

@ujwalgulhane31
The logic is u have to count frequency of a and b in the string and return minimum of them.
i have written this code in much simpler way hope u will get it.
// Update the code below to solve this problem

include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;

while(t--)
{
    string s;
    cin >> s;
    int a=0,b=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='a')
        a++;
        else
        b++;
    }
    cout<<min(a,b)<<endl;
}

}