#K50817. Integer to Roman Numeral Conversion

    ID: 28949 Type: Default 1000ms 256MiB

Integer to Roman Numeral Conversion

Integer to Roman Numeral Conversion

Given an integer num satisfying \(1 \le num \le 3999\), convert it to its Roman numeral representation. The Roman numeral system is based on the following symbols and their values:

  • \(M = 1000\)
  • \(CM = 900\)
  • \(D = 500\)
  • \(CD = 400\)
  • \(C = 100\)
  • \(XC = 90\)
  • \(L = 50\)
  • \(XL = 40\)
  • \(X = 10\)
  • \(IX = 9\)
  • \(V = 5\)
  • \(IV = 4\)
  • \(I = 1\)

The algorithm subtracts the largest possible value repeatedly until the number is reduced to zero, appending the corresponding Roman symbols along the way.

inputFormat

A single integer is provided from the standard input (stdin).

outputFormat

Output the corresponding Roman numeral as a string to the standard output (stdout).## sample

1
I