Wednesday 7 January 2015

Write an algorithm to convert the given input string to the expected output string. The input string shall be the length of few million characters. So the output has to be updated in the same string...

Input String = "ABBCDEFGGGGGGGGHHXX
Expected output = "A1B2C1D1E1F1G8H2X2

#include <stdio.h> 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