#C5113. Run-Length Encoding Compression

    ID: 48727 Type: Default 1000ms 256MiB

Run-Length Encoding Compression

Run-Length Encoding Compression

This problem requires you to implement a run-length encoding algorithm which compresses a given string by replacing consecutive identical characters with the character followed by the count of its occurrences. For example, the string aaabcc should be compressed as a3b1c2.

You need to read the input string from standard input (stdin) and output the compressed string to standard output (stdout).

Note: If the input string is empty, your program should output an empty string.

The encoding strategy is defined as follows:

  • Traverse through the string, keeping track of the current character and its count.
  • Once a different character is encountered, append the current character followed by its count to the result string.
  • Finally, output the concatenated result.

Example: wwwwaaadexxxxxxywww is encoded as w4a3d1e1x6y1w3.

inputFormat

The input consists of a single line containing the string to be compressed. The string may contain upper and lower case letters and may be empty.

outputFormat

Output the run-length encoded string. If the input is an empty string, output an empty string.

## sample
aaabcc
a3b1c2