#C10612. String Compression
String Compression
String Compression
Given a string s
consisting of lowercase English letters, compress the string by replacing consecutive groups of the same character with the character followed by the number of occurrences. If a character appears alone (i.e. it does not have consecutive duplicates), it remains unchanged. Formally, for a string \( s \), if a character \( c \) repeats \( k \) times consecutively and \( k > 1 \), then it is replaced by \( c\,k \); if \( k = 1 \), it is left as is.
For example, the string aaabbccddd
should be compressed to a3b2c2d3
. The solution must read from standard input and write the result to standard output.
inputFormat
The input consists of a single line containing a string s
(1 ≤ |s| ≤ 105) composed only of lowercase English letters.
outputFormat
Output the compressed version of the string based on the rules described above. The output should be printed to standard output.
## sampleaaabbccddd
a3b2c2d3