Help me in solving HOWMANYMAX problem

My issue

can anyone approach its solution to me.

My code

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

int main() {
 int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int c = 0;
        for(int i = 0; i < n-2; i++){
            if(s.at(i) == '0' && s.at(i+1) == '1'){
                c++;
            }
        }
//why following line is written
        if(s.at(0) == '1'){
            c++;
        }
        if(s.at(n-2) == '0'){
            c++;
        }
        cout<<c<<endl;
    
	   
	}
}

Problem Link: HOWMANYMAX Problem - CodeChef

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

int main() {
int t;
cin >> t;
while (t–) {
int n;
cin >> n;
string s;
cin >> s;
int c = 0;
for (int i = 0; i < n - 1; i++) {
if (s.at(i) == ‘0’ && s.at(i + 1) == ‘1’) {
c++;
}
}
// Check the last two characters in the loop
if (s.at(n - 2) == ‘0’ && s.at(n - 1) == ‘1’) {
c++;
}
cout << c << endl;
}
return 0;
}