No.518 Sum of Roman Numerals
タグ : / 解いたユーザー数 151
作問者 :
No
/ テスター :
tatuyan_edson
Problem Statement
There are N Roman numerals (R1,R2,R3, …… ,Rn).
What is the result (A) of adding all of these N Roman numerals?
The output must also be in Roman numerals.
However, if the number is greater than MMMCMXCIX (3999 in Arabic numerals),
output "ERROR".
Roman numerals are written by combining the following 7 letters.
I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000
In Roman numerals, repeating a letter 4 times is prohibited.
The following numbers must be written using subtractive notation.
IV = 4, IX = 9, XL = 40, XC = 90, CD = 400, CM = 900
Input
N R1 R2 R3 …… Rn
N is at least 2 and at most 100,
R is a Roman numeral from I to MMMCMXCIX (1 to 3999 in Arabic numerals)
Output
Output A as a string of Roman numerals.
If the number is greater than MMMCMXCIX (3999 in Arabic numerals), output "ERROR".
Print a newline at the end.
Sample
Sample 1
Input
2 II III
Output
V
2 + 3 = 5
Sample 2
Input
5 IV XXI CCCXL III MMCMVI
Output
MMMCCLXXIV
4 + 21 + 340 + 3 + 2906 = 3274
Sample 3
Input
4 M M M M
Output
ERROR
1000 + 1000 + 1000 + 1000 = 4000
The value exceeds the range, so "ERROR"
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。