Roman numerals are written with seven symbols: I (1), V (5), X (10), L (50), C (100), D (500), and M (1000).
Numbers are generally written largest symbol first. The exception is six subtractive cases, where a smaller symbol precedes a larger one to mean subtraction:
IV = 4 and IX = 9XL = 40 and XC = 90CD = 400 and CM = 900Given an integer num, convert it to a Roman numeral string.
Input / output
num: intstring — the Roman numeral1 <= num <= 3999The thirteen value/symbol pairs (including the six subtractive ones) are chosen so a single greedy pass always produces the canonical numeral. Why does greedily subtracting the largest usable value never paint you into a corner?