Roman numbers (1) P18298


Statement
 

pdf   zip

thehtml

Write a program that reads several numbers and prints their equivalent Roman number.

Remember that Roman numbers make use seven uppercase letters, which correspond to the following values:

||
Letter I V X L C D M
Value 1 5 10 50 100 500 1000
||

These are the rules of Roman numbers:

  • Each decimal digit is computed independently.
  • Units (1, 2, …, 9) are represented, respectively, I, II, III, IV, V, VI, VII, VIII, IX. Nothing is written for 0.
  • Tens (10, 20, …, 90) are written like units are, but repacing I by X, V by L, and X by C.
  • Hundreds (100, 200, …, 900) are written like units are, but repacing I by C, V by D, and X by M.
  • Thousands (1000, 2000 i 3000) are written like units are, but repacing I by M.

Input

Input consists of several natural numbers between 1 and 3999. (Roman people did not know zero, and the system described above cannot represent numbers greater than or equal to 4000.)

Output

For each number, print its equivalent Roman number.

Public test cases
  • Input

    1
    4
    10
    40
    41
    16
    2708
    999
    3005
    

    Output

    1 = I
    4 = IV
    10 = X
    40 = XL
    41 = XLI
    16 = XVI
    2708 = MMDCCVIII
    999 = CMXCIX
    3005 = MMMV
    
  • Information
    Author
    Jordi Petit
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    C C++ Java Python