Difficulty:
Given a Roman numeral less than
4,000, convert it to a decimal number. This Wikipedia article describes Roman numerals in details, but here is a brief description:Roman numerals consist of the following symbols:
Iis 1
Vis 5
Xis 10
Lis 50
Cis 100
Dis 500
Mis 1,000A numeral is formed by a sequence of these symbols, where each symbol can be used up to 3 times to contribute to the total. Symbols are ordered left-to-right from larger to smaller, except for the following cases:
Iplaced beforeVorXindicates one less, so 4 isIV(one less than 5) and 9 isIX(one less than 10)
Xplaced beforeLorCindicates ten less, so 40 isXL(ten less than 50) and 90 isXC(ten less than 100)
Cplaced beforeDorMindicates a hundred less, so 400 isCD(a hundred less than 500) and 900 isCM(a hundred less than 1,000)For example, 11 is
XI, 98 isXCVIII, 99 isXCIXand 1944 isMCMXLIV.
romanToDecimal("MMXVI");2016