#C9423. Separate Consecutive Duplicates
Separate Consecutive Duplicates
Separate Consecutive Duplicates
You are given a string consisting of lowercase alphabets. Your task is to transform the string by compressing consecutive duplicate characters into a single instance of that character followed by the number of times it appears consecutively. For example, the string aaabb
will be transformed into a3b2
.
Note: The input will be provided via standard input (stdin) and the output must be printed to standard output (stdout). The output should not contain any extra characters or spaces.
Examples:
- If the input is
aaabb
, then the output should bea3b2
. - If the input is
abc
, then the output should bea1b1c1
. - If the input is
hhheeellllooo
, then the output should beh3e3l4o3
.
inputFormat
The input consists of a single line containing a non-empty string of lowercase alphabets.
Input Format:
<string>
outputFormat
Output a single line representing the transformed string where each set of consecutive duplicate characters has been replaced with the character followed by the count of its repetitions.
Output Format:
<transformed_string>## sample
aaabb
a3b2