#C10759. String Compression
String Compression
String Compression
Given a string s, compress it using the following algorithm: For each maximal substring of consecutive identical characters, replace it with the character followed by the number of repetitions if the count is greater than 1; otherwise, output the character alone.
For instance, if s = "aaabbccdee"
, then the compressed string is a3b2c2de2
.
Formally, for each group of consecutive identical characters c with length n, output:
\( c \quad if\; n = 1 \quad or \quad c + n \quad if \; n > 1 \)
Your task is to implement this compression algorithm.
inputFormat
The input consists of a single line containing the string s. The string is non-empty and contains only lowercase English letters.
outputFormat
Output the compressed string on a single line, following the described algorithm.
## sampleaaabbccdee
a3b2c2de2