Input String = "ABBCDEFGGGGGGGGHHXX
Expected output = "A1B2C1D1E1F1G8H2X2
#include
void main()
{
char *s="ABBCDEFGGGGGGGGHH";
char *ptr;
char c;
int count=1;
ptr=s;
c=*s;
while(*ptr){
if(*ptr==c)
{
count++;
ptr++;
}
else
{
printf("%c%d",c,count);
count=0;
c=*ptr;
}
}
printf("%c%d",c,count);
}
No comments:
Post a Comment