dsa · medium

Integer to Roman

Convert a positive integer num into a Roman numeral using I, V, X, L, C, D, M. Use the subtractive pairs IV, IX, XL, XC, CD, CM. Prefer the greedy largest symbol that still fits.

Arguments

Example

1994MCMXCIV (M + CM + XC + IV).

Constraints

1 <= num <= 3999

Examples

Example 1

Input:
3

Expected:
III

Example 2

Input:
58

Expected:
LVIII

Example 3

Input:
1994

Expected:
MCMXCIV

Open in the Dojo editor