my code is having problems whenever count of a character is 1. please help
Problem coming when count of a character is 1
@Akshita99 hey ankita take a character array
and do this
int len = strlen(str);
for(i=0;i<len;i++)
{
int count=1;
while(str[i]==str[i+1] && i<len-1)
{
count++;
i++;
}
cout<<str[i]<<count;
}
i did it with this method but i also wanted to try and make changes in the string itself because somewhere we may be asked to return the string to the main program
please solve my doubt
@Akshita99
Use this code snippet.
int i = 0;
while (i < s.size())
{
int j = i + 1;
while (s[i] == s[j])
{
j++;
}
string ros = s.substr(j);
s = s.substr(0, i + 1) + (char)(j - i + '0') + ros;
i += 2;
}