Encoding Binary Numbers
InterviewTime limit1sMemory limit128 MB
Encode each binary string as run lengths followed by digits and print the result per line.
- Level
Easy1 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
A binary number can be encoded into decimal digits by counting how many times each digit repeats in a row.
Read the binary number from the left and cut it into the longest possible runs of one repeated digit. Write each run as its length followed by the digit that repeats, then join the pieces in order.
Input
Each line of the input holds a character string representing a binary number. The length of the binary number on each line is between 1 and 100 inclusive. A line that holds the single character 0 marks the end of the input, and that last line is not encoded. The input holds at most 1,000 lines.
Output
Print the decimal digits for each binary number, one per line. There is no space between digits.