#C11386. String Compression
String Compression
String Compression
You are given a string S. Your task is to compress the string using run-length encoding. In other words, for each group of consecutive identical characters, write the character followed by the number of occurrences if the character repeats more than once.
For example, if a character c appears consecutively n times, then it is represented as c n where n > 1
. The number n should be appended directly after the character without any spaces. If n = 1, only the character is used.
Note: All formulas are represented in LaTeX format. For instance, a group of characters is compressed as: \( c \) if \( n = 1 \), and \( c\,n \) if \( n > 1 \).
inputFormat
The input is read from standard input (stdin) and consists of a single line containing the string S. The string may contain only English letters. The length of the string is at least 0 and can be large.
outputFormat
Output the compressed form of the string to standard output (stdout). For each consecutive group of characters, output the character and, if the group length is greater than one, append the count immediately after the character.
## sampleaaabbccccddddd
a3b2c4d5