#K8751. Run-Length Encoding
Run-Length Encoding
Run-Length Encoding
Given a string s
, your task is to implement its run-length encoding. The run‐length encoding compresses the string by replacing consecutive occurrences of the same character with that character followed by the number of times it appears consecutively.
For example, if s = "aaabbcccc"
, the encoded string should be "a3b2c4"
.
Note: If the input string is empty, the output should be an empty string.
Input Format: The input is read from standard input (stdin) as a single line string.
Output Format: Print the run-length encoded string to standard output (stdout).
inputFormat
The input consists of a single line that contains the string s
.
Constraints:
- The string length can be zero or more.
- The string may consist of any printable characters.
outputFormat
Print the run-length encoded version of the provided string. For each group of consecutive identical characters, output the character followed by the count of its repetitions.
## sampleaaabbcccc
a3b2c4