Roman numbers system has the symbols
I V X L C D M
1 5 10 50 100 500 1000
Roman Numbers are formed by combining the above symbols together and adding the values. For example, MMVI is 1000 + 1000 + 5 + 1 = 2006. Generally:
• Symbols are placed in order of value, starting with the largest values.
• When smaller values precede larger values, the smaller values are subtracted from the larger values e.g. IV is 4, IX is 9, and CM is 900.
• When smaller values follow larger values, the smaller values are added to the larger values e.g. VIII is 8, DX is 510, and LXX is 70.
• The symbols I, X, C, and M can be repeated three times in succession, but no more. (They may appear more than three times if they appear non-sequentially, such as XXXIX.)
• The symbols V, L, and D can never be repeated.
• Only one small-value symbol may be subtracted from any large-value symbol according to the following:
o I can be subtracted from V and X only.
o X can be subtracted from L and C only.
o C can be subtracted from D and M only.
o V, L, and D can never be subtracted.
Examples:
MCMXLIV 1000 + (1000 − 100) + (50 − 10) + (5 − 1) 1944
MCMLIV 1000 + (1000 – 100) + 50 + (5 – 1) 1954
MCMXC 1000 + (1000 – 100) + (100 – 10) 1990
LXXVIII 50 + 10 + 10 + 5 + 1 + 1 + 1 78
CCCLXIX 100 + 100 + 100 + 50 + 10 + (10 – 1) 369
MMDCCLI 1000 + 1000 + 500 + 100 + 100 + 50 + 1 2751
DCCCXC 500 + 100 + 100 + 100 + (100 – 10) 890
Write a program that prompts the user to enter a string of symbols representing a Roman number. The program converts that roman number to its equivalent decimal number, and then prints both numbers.
If roman is a variable of type string, then roman[0] stores the first character in the string, roman[1] stores the second character in the string, roman[2] stores the third character in the string, and so on.