10135_PrefaceNumbering

2022-5-16 18:16| 发布者: Hocassian| 查看: 110| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504586188100-Problem List-采集的数据-后羿采集器.html

Pro.ID

10135

Title

Preface Numbering

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10135

AC

40

Submit

80

Ratio

50.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    A certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain subset of decimal numbers. Here is the standard set:

    I   1     L   50    M  1000
    V   5     C  100          
    X  10     D  500          

    As many as three of the same marks that represent 10n may be placed consecutively to form other numbers:

    • III is 3

    • CCC is 300

    Marks that have the value 5×10n are never used consecutively.

    Generally (with the exception of the next rule), marks are connected together and written in descending order to form even more numbers:

    • CCLXVIII = 100+100+50+10+5+1+1+1 = 268

    Sometimes, a mark that represents 10n is placed before a mark of one of the two next higher values (I before V or X; X before L or C; etc.). In this case, the value of the smaller mark is SUBTRACTED from the mark it precedes:

    • IV = 4

    • IX = 9

    • XL = 40

    This compound mark forms a unit and may not be combined to make another compound mark (e.g., IXL is wrong for 39; XXXIX is correct).

    Compound marks like XD, IC, and XM are not legal, since the smaller mark is too much smaller than the larger one. For XD (wrong for 490), one would use CDXC; for IC (wrong for 99), one would use XCIX; for XM (wrong for 990), one would use CMXC. 90 is expressed XC and not LXL, since L followed by X connotes that successive marks are X or smaller (probably, anyway).

    Given N (1 ≤ N < 3,500), the number of pages in the preface of a book, calculate and print the number of I's, V's, etc. (in order from lowest to highest) required to typeset all the page numbers (in Roman numerals) from 1 through N. Do not print letters that do not appear in the page numbers specified.

    If N = 5, then the page numbers are: I, II, III, IV, V. The total number of I's is 7 and the total number of V's is 2.

    输入

    Multiple test cases. Each case has a single line containing the integer N.

    输出

    Description

    A certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain subset of decimal numbers. Here is the standard set:

    I   1     L   50    M  1000
    V   5     C  100          
    X  10     D  500          

    As many as three of the same marks that represent 10n may be placed consecutively to form other numbers:

    • III is 3

    • CCC is 300

    Marks that have the value 5×10n are never used consecutively.

    Generally (with the exception of the next rule), marks are connected together and written in descending order to form even more numbers:

    • CCLXVIII = 100+100+50+10+5+1+1+1 = 268

    Sometimes, a mark that represents 10n is placed before a mark of one of the two next higher values (I before V or X; X before L or C; etc.). In this case, the value of the smaller mark is SUBTRACTED from the mark it precedes:

    • IV = 4

    • IX = 9

    • XL = 40

    This compound mark forms a unit and may not be combined to make another compound mark (e.g., IXL is wrong for 39; XXXIX is correct).

    Compound marks like XD, IC, and XM are not legal, since the smaller mark is too much smaller than the larger one. For XD (wrong for 490), one would use CDXC; for IC (wrong for 99), one would use XCIX; for XM (wrong for 990), one would use CMXC. 90 is expressed XC and not LXL, since L followed by X connotes that successive marks are X or smaller (probably, anyway).

    Given N (1 ≤ N < 3,500), the number of pages in the preface of a book, calculate and print the number of I's, V's, etc. (in order from lowest to highest) required to typeset all the page numbers (in Roman numerals) from 1 through N. Do not print letters that do not appear in the page numbers specified.

    If N = 5, then the page numbers are: I, II, III, IV, V. The total number of I's is 7 and the total number of V's is 2.

    Input

    Multiple test cases. Each case has a single line containing the integer N.

    Output

    For each case, the output lines specify, in ascending order of Roman numeral letters, the letter, a single space, and the number of times that letter appears on preface page numbers. Stop printing letter totals after printing the highest value letter used to form preface numbers in the specified set.

    Output a blank line after each case.

    Sample Input

    5
    20

    Sample Output

    I 7
    V 2

    I 28
    V 10
    X 14

    Source

    样例输入

    5
    20

    样例输出

    I 7
    V 2

    I 28
    V 10
    X 14

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部