Although you have learned about Roman numerals for years, you have probably
not heard about a variation of them, the Pompeiian numerals. You probably
remember much of Pompeii was destroyed when Vesuvius exploded, but a few
residents survived, and continued to use the Roman numeral system. Unfortunately,
these survivors lost their little fingers as a result of the explosion,
so their number system is based on a base 8 number system, instead of a
base 10 number system, even though it uses the same symbols as Roman numerals.
So, the Pompeiian numeral system has the following association of symbols
to numbers:
Poempeiian | Decimal |
I | 1 |
V | 4 |
X | 8 |
L | 32 (= V * X) |
C | 64 (= X * X) |
D | 256 (= V * C) |
M | 512 (= X * C) |
As with Roman numerals, the position of letters is important. If symbols are the same or decrease in value from left to right, their values were added; however, if a symbol had a smaller value than a symbol on its right, it is to be subtracted. For example, CX = 64 + 8 = 72, but XC = 64 - 8 = 56.
No more than two identical symbols are used in succession. For example, IV is used for 3 instead of III. Likewise, there are never more than two symbols involved in the subtractive feature. The only subtractive symbol combinations allowed are IV, IX, XL, XC, CD, and CM.
Write a Pompeiian Numeral Converter that reads Pompeiian numerals from a file and writes their decimal equivalents to a file, one per line.