#K791. Run-Length Encoding and Decoding
Run-Length Encoding and Decoding
Run-Length Encoding and Decoding
This problem involves implementing two algorithms: Run-Length Encoding (RLE) and its inverse, Run-Length Decoding. Run-Length Encoding compresses a string by replacing consecutive identical characters with a count followed by the character. For example, the string (AAAABBBCCDAA) is encoded as (4A3B2C1D2A). Conversely, decoding converts such a compressed string back to its original form.
In this contest problem, you are given several test cases. For each test case, if the input string begins with a letter, you are required to encode it using the RLE method. If it begins with a digit, you should decode it. Your solution should read input from standard input (stdin) and print the answer to standard output (stdout).
inputFormat
The first line contains an integer (T) representing the number of test cases. Each of the next (T) lines contains a single string. For each string, if the first character is a digit, decode it; otherwise, encode it using Run-Length Encoding.
outputFormat
For each test case, output the transformed string on a new line. The transformation is encoding if the original string is not encoded, and decoding if it is encoded.## sample
2
AAAABBBCCDAA
4A3B2C1D2A
4A3B2C1D2A
AAAABBBCCDAA
</p>