#12

Integer to Roman

specialist · 615 · lc medium +29 · verified · 70.5% accepted · 8,475 likes · top 79%

play →

Description

The seven Roman numeral symbols are I(1), V(5), X(10), L(50), C(100), D(500), and M(1000). Subtractive forms 4(IV), 9(IX), 40(XL), 90(XC), 400(CD), 900(CM) are used where applicable. I, X, C, M may repeat consecutively at most three times; V, L, D cannot repeat. Convert the given integer to its Roman numeral string.

Example 1:

3000 = MMM as 1000 (M) + 1000 (M) + 1000 (M)
700 = DCC as 500 (D) + 100 (C) + 100 (C)
40 = XL as 10 (X) less of 50 (L)
9 = IX as 1 (I) less of 10 (X)
Note: 49 is not 1 (I) less of 50 (L) because the conversion is based on decimal places

Example 2:

50 = L
8 = VIII

Example 3:

1000 = M
900 = CM
90 = XC
4 = IV

Code

1
2
3