Problem Statement: The string contains multiple characters that are repeated consecutively. Now, write a program that will reduce the size of the string using the given mathematical logic.
Sample Test Case:
Input: abbcccddddeeeee
Output: a1b2c3d4e5
Program in C:
//Learnprogramo - programming made simple
#include<stdio.h>
int main() {
char str[100];
scanf("%[^\n]s",str);
int k=0, i, j, count = 0;
char str1[100];
for(i = 0; str[i] != '\0'; i++)
{
count = 0;
for(j = 0; j <= i; j++)
{
if(str[i] == str[j])
{
count++;
}//if..
}//for...
if(count==1)
{
str1[k] = str[i];
k++;
}//if..
}//for..
for(i=0; i<k; i++)
{
count = 0;
for(j=0; str[j]!='\0'; j++)
{
if(str1[i]==str[j])
{
count++;
}//if..
}//for..
if(count==1)
{
printf("%c",str1[i]);
}//if..
else
{
printf("%c%d",str1[i],count);
}//else..
}//for..
return 0;
}