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