Compress
Time limit1sMemory limit128 MB
Given pairs F and R with F < R, print F and the shortest compressed form C that decodes back to R.
- Level
Medium4 of 10
- Topics
- String, Implementation, Math
- Solved
- No attempts yet
Problem
Reduce the number of digits.
An experimental physicist generates a huge amount of data. The data has a special property, and he wants to exploit it to shrink the space needed to store the results.
The data comes as pairs of numbers where the first number is always smaller than the second. He wants to store each pair much the way people abbreviate a range of pages in a book: instead of writing "pages 11 through 18" they sometimes write "11-8".
Notation
Decoding a compressed second number
Leading zeros in are significant: "7", "07" and "007" are all different. For example:
- for "2839-06": , , so
- for "2839-006": , , so
Your task is the reverse of decoding: given each uncompressed pair and , output the compressed second number using the fewest possible digits.
Input
Each line contains a pair of non-negative integers separated by a hyphen. The second number is always larger than the first, and the second number is always less than . Read lines until end of file.
Output
For each input line, print one line containing the first number, a hyphen, and the compressed form of the second number.