#K79932. String Compression
String Compression
String Compression
You are given a string s
consisting of alphabetic characters. Your task is to compress the string by replacing each group of consecutive identical characters with the character followed by the count, but only if the count is greater than 1. Otherwise, include the character as it is.
For example, if s = "aabcccccaaa"
, then the compressed string is computed as follows:
\( \text{compress}(s) = a2 \, b \, c5 \, a3 \)
If the string does not contain any consecutive repeating characters, then the output is the original string. Your solution should read the input from stdin and write the output to stdout.
inputFormat
The input consists of a single line containing the string s
. The string may be empty and contains only alphabetic characters.
outputFormat
Output the compressed string as described. If a character appears consecutively and the count is greater than one, output the character immediately followed by the number (in decimal). Otherwise, simply output the character.
## sampleaabcccccaaa
a2bc5a3