#CT00044. Nén bản tin (Message Compression)
Nén bản tin (Message Compression)
Message Compression
Version: Phuoc Hung OJ Extended
Problem Statement
A message is represented by a string containing only uppercase English letters from A to Z.
Compress each maximal run of equal consecutive characters as follows:
- A run of length is kept as the character itself.
- If a character appears consecutively times with , replace the run by followed by the decimal representation of .
For example, AAABBCCCCDAA becomes A3B2C4DA2.
Construct the compressed string and determine its length .
Input
One line contains the string .
Output
- The first line contains the compressed string .
- The second line contains the integer .
Subtasks
- Subtask 1 (40%): .
- Subtask 2 (30%): .
- Subtask 3 (30%): .
Examples
Example 1
Input
AAABBCCCCDAA
Output
A3B2C4DA2
9
Explanation
The runs are AAA, BB, CCCC, D, AA, with lengths . They become A3, B2, C4, D, A2.
Example 2
Input
ABCDE
Output
ABCDE
5
Explanation
Every run has length , so the string is unchanged.
Example 3
Input
AAAAAAAAAAAA
Output
A12
3
Explanation
There are consecutive A characters, so the run is represented by A12, whose length is .
Liên quan
Trong các cuộc thi sau: