AtlassianOA #1
Better Compression
Estimated EasyJudge-ready
The input consists of lowercase letters, each followed by a positive decimal frequency, and the same letter may appear multiple times. Accumulate the frequencies, then in ascending letter order output each letter that occurs, listed only once together with its total frequency.
Input
A single line containing the compressed string S. Original bounds: 1≤|S|≤100000; each segment has a letter a..z and a frequency 1..1000; the input must be a complete valid letter-frequency sequence, so a valid string has length at least 2. This site uses frequency encoding without leading zeros.
Output
Output the unique canonical compressed string.
Example 1
Input:
a3c9b2c1
Output:
a3b2c10
Example 2
Input:
z1000a1z10
Output:
a1z1010
Example 3
Input:
a1
Output:
a1
Example notes
The outputs of the three public examples are, in order: a3b2c10; a1z1010; a1. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…