#K65152. String Compression
String Compression
String Compression
You are given a string s
consisting of lowercase Latin letters. Your task is to compress the string by replacing every maximal sequence of identical characters with the character followed by the number of its occurrences.
For example, the string aaabbc
is compressed to a3b2c1
and the string abcd
is compressed to a1b1c1d1
.
The solution should read input from standard input (stdin
) and print the result to standard output (stdout
).
Note: For any character c that appears consecutively n times, the output should include c concatenated with the number n. In mathematical terms, if a sequence of character c appears n times consecutively, then the result will include c n
(written as c{n}
in LaTeX, i.e. \(c\,\{n\}\)).
inputFormat
The input consists of a single non-empty string s
provided via standard input (stdin
). The string s
contains only lowercase Latin letters.
outputFormat
Output the compressed form of the input string to standard output (stdout
).
aaabbc
a3b2c1