Integer to Roman Numeral
easyStrings II+10 XPTime limit 2s
Write each number as a Roman numeral in standard form: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000, symbols from largest to smallest, and the subtractive pairs IV = 4, IX = 9, XL = 40, XC = 90, CD = 400, CM = 900 used whenever needed (never write IIII or VIV). For example 2026 = MMXXVI and 49 = XLIX.
Input:
- line 1:
q - next
qlines: one integerneach
Output: q lines — each number as a Roman numeral.
Constraints: 1 ≤ q ≤ 10⁴, 1 ≤ n ≤ 3999.
Think about it: greedy. List the 13 values 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 with their symbols. Repeatedly take the largest value that still fits, append its symbol and subtract it.
Sample input 1
3 2026 49 3
Sample output 1
MMXXVI XLIX III
Sample input 2
2 3999 1
Sample output 2
MMMCMXCIX I
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).