#C12313. Run-Length Encoding
Run-Length Encoding
Run-Length Encoding
You are given a non-empty string s
. Your task is to implement run-length encoding on this string. In run-length encoding, consecutive occurrences of the same character are replaced by the character followed by the count of its repetitions.
For example, if s = "aaabbccca"
, then its run-length encoding is a3b2c3a1
. Similarly, for s = "abc"
, the encoding is a1b1c1
.
If the input string is empty, you should output an error message: Input string is empty
.
The input string is provided via standard input (stdin) and the answer should be printed to standard output (stdout).
inputFormat
A single line string s
read from stdin. The string may contain only alphabets. It is guaranteed that the string is non-empty for valid test cases; however, if an empty string is provided, the program should output an error message.
outputFormat
A single line string representing the run-length encoding of the input. For invalid input (empty string), output the error message Input string is empty
.## sample
aaabbccca
a3b2c3a1