Blog # 58 : Run Length Encoding (RLE)
Run-length encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. Count of 1 is not indicated. Write a program to find RLE of given string. Eg. input = "aabbbcddeef" RLE = "a2b3cd2e2f" input = "aaabbcddeeeef" RLE = "a3b2cd2e4f" Click here to see the solution. p.s. - For Remarks please hit the given link once. For Hint, hit it twice and for the solution, hit it thrice. Courtesy: Vibhaj |
your code has got bug...
if run exceeds length 9..
Thanks for pointing it out ...
That may be easily solved by using sprintf() to print the count into output[] rather than using offset from '0' which fails for count greater than 9.