This code runs perfectly fine as per the given questions but still i'm unable to pass testcases. Can u tell where the logic is wrong in this code

#include
#include <string.h>
using namespace std ;

void perfect_it(char str[], int n)
{
int len = strlen(str) ; // Sample Input is 2,abba, output shd be 4 (bbbb or aaaa)
int temp = n ;
int count = 0, count_temp = 0 ;
for (int i = 0; i < len; i++) // ababab
{
if (str[i] != str[i + 1])
{
while(temp > 0)
{
str[i + 1] = str[i] ;
temp-- ;
break ;
}
count++ ;
}
}

for (int i = 0; i < len; i++)
{
	if (str[i] == str[i+1])
	{
		count_temp++ ;
	}
}

// if (count_temp == len)
// {
// 	cout<<count_temp ;
// }
int res = count_temp + 1 ;
cout<<res ;

}

int main ()
{
char str[1000] ;
int n ;
cin>>n ;
cin.get() ;
cin.getline(str, 1000) ;
perfect_it(str,n) ;

return 0 ;

}

hi @kartikey.rajput0071 send code on ide.codingblocks.com

shared code on (https://ide.codingblocks.com/)

hi @kartikey.rajput0071,
login
write
save
share the url of page

Ok
Coding Blocks IDE

hi @kartikey.rajput0071 ive asked the question from team please wait

yes sure, thanks @talhashamim001

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.