Roman Numeral Translation

4.5

6 votes
Problem

A Roman numeral consists of a set of letters of the alphabet, each letter has a particular value, as shown in the following table:

enter image description here

Generally, Roman numerals are written in descending order from left to right, and are added sequentially. However, certain combinations employ a subtractive principle. If a symbol of lower value appears to the left of a larger value, the smaller value is subtracted from the larger value, and the result is added to the total.

“I” may only precede “V” and “X”: IV = 4, IX = 9

“X” may only precede “L” and “C”: XC = 90, XL = 40

“C” may only precede “D” and “M”: CM = 900, CD = 400

“V”, “L”, and “D” are always followed by a symbol of smaller value so they are always added to the total.

Symbols “I”, “X”, “C”, and “M” cannot appear more than three consecutive times “XXX” = 30, but “XXXX” is not equal to 40.

Roman numerals do not include the number zero.

Your task is to write a program that converts from Arabic numerals to Roman numerals.


INPUT:
There will be 100 inputs, one line per input. 0 < input < 4000.


OUTPUT:
Output the equivalent Roman numeral of the input, one per line. Use only uppercase letters.

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?