4 人解决,6 人已尝试。
4 份提交通过,共有 9 份提交。
7.6 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
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:
Symbol | I | V | X | L | C | D | M |
---|---|---|---|---|---|---|---|
Value | 1 | 5 | 10 | 50 | 100 | 500 | 1000 |
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:
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.
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.
2 XII MDL 4 I I I I 0
Case I: MDLXII Case II: IV
4 人解决,6 人已尝试。
4 份提交通过,共有 9 份提交。
7.6 EMB 奖励。