#C3748. Run-Length Encoding
Run-Length Encoding
Run-Length Encoding
This problem requires you to implement the Run-Length Encoding (RLE) algorithm. Given a string containing only lowercase alphabets, your task is to compress the string by replacing consecutive occurrences of the same character with the character followed by the count of its occurrences.
For example, given the string aaabbc
, the output should be a3b2c1
. The encoding should be performed from left to right. In mathematical terms, for a character c repeated k times consecutively, the result should include c concatenated with k (i.e. $c\,k$ in LaTeX format).
If the string is empty, output an empty string.
inputFormat
The input consists of a single line containing a string s
that consists of only lowercase alphabets. Note that the string may be empty.
outputFormat
Output the run-length encoded string corresponding to the input.
## sampleaaabbc
a3b2c1