#CT0000071. Mã hóa bản tin (Message Encoding)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Mã hóa bản tin (Message Encoding)
Message Encoding
Version: Phuoc Hung OJ Extended
Problem Statement
A message is a string containing only uppercase English letters from A through Z.
To encode the message, replace every maximal group of equal consecutive characters with the character followed by the number of characters in that group. Write the count in decimal notation without leading zeros.
For instance, AAABB becomes A3B2: the first group contains three A characters, and the second contains two B characters. Even a group containing just one character must include the count 1. The groups retain their original order.
Task: Produce the encoded form of .
Input
One line containing , with no spaces and consisting only of A–Z.
Output
Print the encoded string on one line.
Subtasks
- Subtask 1 (30 points): ; all characters are
A–Z. - Subtask 2 (30 points): ; all characters are
A–Z; each maximal group of equal consecutive characters has length from to . - Subtask 3 (40 points): ; all characters are
A–Z.
Examples
Example 1
Input
AAABCCCCDDDA
Output
A3B1C4D3A1
Explanation
The consecutive groups are AAA, B, CCCC, DDD, A, with lengths . They contribute A3, B1, C4, D3, A1, giving A3B1C4D3A1.
Example 2
Input
XYZ
Output
X1Y1Z1
Explanation
The distinct consecutive characters X, Y, Z each form a group of length . As single-character groups still include a count, the result is X1Y1Z1.
Example 3
Input
AAAAAAAAAAAA
Output
A12
Explanation
All twelve A characters belong to one group. The character followed by the decimal count 12 forms A12, not twelve repetitions of A1.
Liên quan
Trong các cuộc thi sau: