Seven different symbols represent Roman numerals with the following values: - I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000. Roman numerals are formed by appending the conversions of decimal place values from highest to lowest. Converting a decimal place value into a Roman numeral has the following rules: - If the value does not start with 4 or 9, select the symbol of the maximal value that can be subtracted from the input, append that symbol to the result, subtract its value, and convert the remainder to a Roman numeral. - If the value starts with 4 or 9 use the subtractive form representing one symbol subtracted from the following symbol, for example, 4 is 1 (I) less than 5 (V): IV and 9 is 1 (I) less than 10 (X): IX. Given an integer, convert it to a Roman numeral.
Example 1
Input: num = 1994
Output: MCMXCIV
Explanation: Break 1994 into place values: 1000 = M, 900 = CM, 90 = XC and 4 = IV. Joined together that is "MCMXCIV".
Example 2
Input: num = 3
Output: III
Explanation: 3 is three 1s, written "III".
Example 3
Input: num = 58
Output: LVIII
Explanation: 58 = 50 + 5 + 3, which is L + V + III = "LVIII".
List every Roman value (including the subtractive forms like 900=CM and 4=IV) from largest to smallest. Repeatedly append the largest symbol that still fits and subtract its value, until the number reaches zero.
Run checks all cases above. Submit evaluates all test cases.