Skip to content
Onsite

Integer to Roman

MediumP3Coding

Convert the integer num to a Roman numeral. The symbols are I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000, and the following six subtractive forms are used: IV = 4, IX = 9, XL = 40, XC = 90, CD = 400, CM = 900.

Write the number from the largest value to the smallest; no symbol is repeated more than three times in a row.

Example 1

Input
num = 3
Output
"III"

Example 2

Input
num = 58
Output
"LVIII"

Example 3

Input
num = 1994
Output
"MCMXCIV"

Constraints

  • 1 <= num <= 3999

Hints

Run checks the 3 visible tests, Submit all 14.