Search across blog, articles, projects, courses, and community posts
Run-length encoding replaces each run of the same letter with the letter followed by the length of the run. For example aaabcc becomes a3b1c2. Read a word and print its encoding.
Input: one line of lowercase letters.
Output: the encoded string.
The word has 1 to 1000 lowercase letters. A single letter is written with a count of 1.
aaabcc
a3b1c2
abc
a1b1c1