22575_CIVICDILLMIX

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

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

Pro.ID

22575

Title

CIVIC DILL MIX

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Roman numerals are an ancient numbering system used extensively throughout Europe through the 13th century (where it was eventually replaced by our current positional system). Vestiges of this system still exist today on clock faces, building cornerstones, Super Bowls and Star Wars episodes. The system uses the following 7 symbols:

    Symbols I, X, C and M can be repeated as needed (though never more than three times for I, X and C), so that 3 is represented as III, 27 as XXVII and 4865 as MMMMDCCCLXV. The symbols are always written from the highest value to the lowest, but for one exception: if a lower symbol precedes a higher one, it is subtracted from the higher. Thus 4 is written not as IIII but as IV, and 900 is written as CM.
    The rules for this subtractive behavior are the following:

    1. Only I, X and C can be subtracted.

    2. These numbers can only appear once in their subtractive versions (e.g., you can't write 8 as IIX).

    3. Each can only come before symbols that are no larger than 10 times their value. Thus we can not write IC for 99 or XD for 490 (these would be XCIX and CDXC, respectively). Note that the first two words in this problem title are invalid Roman numerals, but the third is fine.

    Your task for this problem is simple: read in a set of Roman numeral values and output their sum as a Roman numeral.

    输入

    Input will consist of multiple test cases. Each test case starts with a positive integer n indicating the number of values to add. After this will come n values (potentially several on a line), all valid Roman numerals with whitespace only coming between values. A value of n = 0 will indicate end of input. All sums will be less than 5000.

    输出

    Description

    Roman numerals are an ancient numbering system used extensively throughout Europe through the 13th century (where it was eventually replaced by our current positional system). Vestiges of this system still exist today on clock faces, building cornerstones, Super Bowls and Star Wars episodes. The system uses the following 7 symbols:

    Symbols I, X, C and M can be repeated as needed (though never more than three times for I, X and C), so that 3 is represented as III, 27 as XXVII and 4865 as MMMMDCCCLXV. The symbols are always written from the highest value to the lowest, but for one exception: if a lower symbol precedes a higher one, it is subtracted from the higher. Thus 4 is written not as IIII but as IV, and 900 is written as CM.
    The rules for this subtractive behavior are the following:

    1. Only I, X and C can be subtracted.

    2. These numbers can only appear once in their subtractive versions (e.g., you can't write 8 as IIX).

    3. Each can only come before symbols that are no larger than 10 times their value. Thus we can not write IC for 99 or XD for 490 (these would be XCIX and CDXC, respectively). Note that the first two words in this problem title are invalid Roman numerals, but the third is fine.

    Your task for this problem is simple: read in a set of Roman numeral values and output their sum as a Roman numeral.

    Input

    Input will consist of multiple test cases. Each test case starts with a positive integer n indicating the number of values to add. After this will come n values (potentially several on a line), all valid Roman numerals with whitespace only coming between values. A value of n = 0 will indicate end of input. All sums will be less than 5000.

    Output

    For each test case, output the case number and the sum, both as Roman numerals, using the format shown below. Case numbers should start at I.

    Sample Input

    2
    XII MDL
    4
    I I I
    I
    0

    Sample Output

    Case I: MDLXII
    Case II: IV

    Source

    样例输入

    2
    XII MDL
    4
    I I I
    I
    0

    样例输出

    Case I: MDLXII
    Case II: IV

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部