Menu
CoddyTech

Integer to Roman

Roman numerals have seven letters: M 1000, D 500, C 100, L 50, X 10, V 5 and I 1. Letters go from largest to smallest and add up, so 7 is VII. No letter repeats four times in a row: 4, 9, 40, 90, 400 and 900 are written IV, IX, XL, XC, CD and CM, a smaller letter subtracted from the larger after it. Only these six pairs put a smaller letter first.

Given an integer num, return its Roman numeral.

Function

intToRoman(num: integer) → string
numinteger
an integer from 1 to 3999
Returnsstring
the Roman numeral for num in capital letters

Constraints

  • 1 ≤ num ≤ 3999

Examples

Input
num = 49
Output
"XLIX"
Explanation
49 is 40 + 9, so the numeral is XL then IX: XLIX. IL is not allowed, because I subtracts only in IV and IX.
challenge icon

Follow-up

Given a string, can you check that it is a Roman numeral in this standard form, accepting XLIX and rejecting IIII, IL and VX?

Reset code
def intToRoman(num):
    # Write code here

Test #1

Test #2

Test #3

Argument

num = 49

Expected Output

"XLIX"