#C5620. Run-Length Encoding of a String
Run-Length Encoding of a String
Run-Length Encoding of a String
This problem requires you to perform run-length encoding on a given string. For each maximal group of consecutive identical characters in the string, output a pair consisting of the number of occurrences followed by the character itself. The encoding of each group can be mathematically represented as $$\text{encoded\_group} = count \cdot character$$. For example, the string aaBBccAA
should be encoded as 2a2B2c2A
.
The input string may contain alphabet letters, digits, punctuation marks, and other symbols. Make sure your solution reads the input from standard input (stdin) and writes the result to standard output (stdout).
inputFormat
The input consists of a single line containing the string to be encoded.
outputFormat
Output the encoded string on a single line. This string is the run-length encoding of the input string.
## sampleaaBBccAA
2a2B2c2A