7 人解决,8 人已尝试。
7 份提交通过,共有 8 份提交。
5.2 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
The Romans used letters from their Latin alphabet to represent each of the seven numerals in their number system. The list below shows which letters they used and what numeric value each of those letters represents:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
Using these seven numerals, any desired number can be formed by following the two basic additive and subtractive rules. To form a number using the additive rule the Roman numerals are simply written from left to right in descending order, and the value of each roman numeral is added together. For example, the number MMCLVII has the value 1000 + 1000 + 100 + 50 + 5 + 1 + 1 = 2157. Using the addition rule alone could lead to very long strings of letters, so the subtraction rule was invented as a result. Using this rule, a smaller Roman numeral to the left of a larger one is subtracted from the total. In other words, the number MCMXIV is interpreted as 1000 - 100 + 1000 + 10 - 1 + 5 = 1914.
Over time the Roman number writing system became more standardized and several additional rules were developed. The additional rules used today are:
Your goal is to write a program which converts Roman numbers to base 10 integers.
The input to this problem will consist of the following:
A line with a single integer “N” (1 ≤ N ≤ 1000), where N indicates how many Roman numbers are to be converted.
A series of N lines of input with each line containing one Roman number. Each Roman number will be in the range of 1 to 10,000 (inclusive) and will obey all of the rules laid out in the problem’s introduction.
For each of the N Roman numbers, print the equivalent base 10 integer, one per line.
3 IX MMDCII DXII
9 2602 512
7 人解决,8 人已尝试。
7 份提交通过,共有 8 份提交。
5.2 EMB 奖励。
创建: 16 年,4 月前.
修改: 7 年,4 月前.
最后提交: 1 年,5 月前.