当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2319:COMPRESS

题目描述
Reduce the number of digits.
An experimental physicist generates a great deal of data from experiments that he performs. The data generated from these experiments has a special property, and he wants to take advantage of this property to reduce the amount of space needed to store the results.

The data is generated in pairs of numbers, where the first number is always less than the second number. The way that the physicist wants to store these numbers is similar to the how some people abbreviate a range of numbers in a book. For example, when they refer to pages 11 through 18 in a book, they will sometimes denote it as 11-8.

Some notation definitions:

Definitions
For example
The first of a pair of numbers is denoted by F.
in "18482-02", F = 18482
The second of a pair of numbers (in compressed form) is denoted by C.
in "18482-02", C = 02
The second of a pair of numbers (in decoded form) is denoted by R.
in "18482-02", R = 18502
MSD(x,y) refers to the 'x' most significant digits of 'y' when 'y' is denoted in base ten, which is the null string for x <= 0
MSD(3,19283) = 192, MSD(0,12)=''
LSD(x,y) refers to the 'x' least significant digits of 'y' when 'y' is denoted in base ten (possibly padded with zeros).
LSD(2, 48290) = 90, LSD(2,3)= 03

The rules for decoding the "compressed" second number are as follows:
Rule
An example
The number C is always written with the fewest possible digits.

If the number C is larger than F, then R is the same as C.
given "123-283", then F=123, C=283, and R would be 283
If C is less than or equal to F, then the following rules apply:

LSD(length(C), R) will always be the same as C.

If LSD(length(C), F) is less than C, then R is equal to MSD(length(F) - length(C), F), prepended to the digits of C.
given: "4137-223", then:
F=4137, C=223:
LSD(length(C),R) = 223
MSD(4 - 3, 4137) = 4
R would be 4223
If LSD(length(C), F) is greater than or equal to C, then R is equal to 10^(length(C)) added to the following value: MSD(length(F) - length(C), F), prepended to the digits of C.
given: "8543-13", then
F=8543, C=13:
LSD(length(C),R) = 13
MSD(4 - 2, 8543) = 85
10^(2) = 100
R would be 8513 + 100 = 8613

Please note that leading zeros on the number C are significant. '7' is not the same as '07', and neither of them are the same as '007'. For example:
given: "2839-06", then F=2839, C=06 so R would be 2906
given: "2839-006", then F=2839, C=006 so R would be 3006

Your task is to compute the "compressed" second number format from it's uncompressed version.
输入解释
In the input, each line of input will consist of a pair of non-negative integers separated by a hyphen, where the second number is always larger than the first number. The second number will always be less than 231-1.
输出解释
Each line of input will produce one line of output. Each line of output will consist of the first number, followed by a hyphen, followed by the "compressed" version of the second number.
输入样例
10-18
83294-84137
100-200
输出样例
10-8
83294-137
100-00
提示
Q. Prob. 4 states that c will always be written with the min. digits. The example given as f=4137, c=223 gives r=4223. But if given 4137-4223 as input, the min. digits for c is 23. Are there test cases like this?

A. It is true that 4137-223 is not the smallest possible representation of the range 4137-4223, but, given 4137-223, the correct decompression is 4137-4223.

A program that generated 4137-223 would be judged incorrect because 4137-23 is the shortest compressed representation of this range.

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Rocky Mountain 2003

源链接: POJ-2319

最后修改于 2020-10-29T06:29:42+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536