Roman numerals use seven symbols: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. Numbers are written from the largest symbol to the smallest and their values add up, except for six subtractive pairs where a smaller symbol sits before a larger one: IV = 4, IX = 9, XL = 40, XC = 90, CD = 400 and CM = 900. Only I, X, C and M may repeat, at most three times in a row. Given an integer num, return its Roman numeral.
Roman numerals use seven symbols: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. Numbers are written from the largest symbol to the smallest and their values add up, except for six subtractive pairs where a smaller symbol sits before a larger one: IV = 4, IX = 9, XL = 40, XC = 90, CD = 400 and CM = 900. Only I, X, C and M may repeat, at most three times in a row. Given an integer num, return its Roman numeral.
Example 1:
Input: {"num":3749}
Output: MMMDCCXLIX
Constraints:
1≤num≤3999
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"num":3749}
Line the 13 denominations up from largest to smallest, including the six subtractive pairs, and spend 3749 greedily.
num left to convert
3749
of 3749
paid 0 · left 3749
denominations, largest first (purple = subtractive pair)