Help me in solving BINSTRING problem

My issue

My code 2:

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

int main() 
{
    int GTX; std::cin >> GTX;
    while(GTX>0)
    {
        int n, c=0; cin>>n;
        string s; cin>>s;
        for(int i=1; i<n; i++)
        {
            if(s[i-1]!=s[i])c++;
        }
        
        cout<<c+1;
        cout<<"\n";
        GTX--;
    }
    	
	return 0;
}

My code 2:

int main() {
    int t;
    cin >> t;
    while(t--){
        int n, s, count=0;
        cin >> n >> s;
        string num = to_string(s);
        for (int i=0; i<n-1; i++){
            if (num[i] == num[i+1])
                count++;
        }
        cout << n - count << endl;
    }
    return 0;
}

I don’t know how, but the 2nd Code fails gives wrong answer on submission while the first one gives correct answer on submission, where am i wrong in 2nd code?
Please Help me!

Problem Link: BINSTRING Problem - CodeChef

@jk21102
u can’t take input as int then convert it into string like if n is 10^5 then the string of size 10^5 can’t be stored in int or even long long int

1 Like

Ohh! Sorry i forgot about that. Thanks for helping.