#C602. Run-Length Encoding Compression
Run-Length Encoding Compression
Run-Length Encoding Compression
This problem requires you to implement the Run-Length Encoding (RLE) technique to compress strings. Given a series of strings, your program should compress each string by replacing consecutive occurrences of a character with the character followed by the number of times it appears consecutively. For example, the string aabcccccaaa
would be compressed to a2b1c5a3
.
The encoding algorithm works as follows:
- If the string is empty, output an empty string.
- Otherwise, iterate through the string, count consecutive occurrences of each character, and then append the character and its count to the output.
inputFormat
The input is given via standard input (stdin). The first line contains an integer T representing the number of test cases. Each of the next T lines contains a single string that needs to be compressed using the RLE technique.
outputFormat
For each test case, output the compressed string on a separate line to standard output (stdout).
## sample2
aabcccccaaa
hhhhhgggeeecc
a2b1c5a3
h5g3e3c2
</p>