OVERVIEW
Write a program to convert roman numerals into their arabic equivalent.
INPUT REQUIREMENTS
Read one or more roman numerals from standard input. Do not display an input prompt. Process one line at a time. Each input line contains only one roman numeral, starting in column one. Assume the characters are all upper case with no embedded blanks.
OUTPUT REQUIREMENTS
The arabic equivalent of each input roman numeral is displayed on standard output, starting in column one.
FUNCTIONAL REQUIREMENTS
Here are the arabic equivalents for roman symbols:
The "basic" roman
symbols
The "auxiliary" roman symbols
I X C M V L D1 10 100 1000 5 50 500
Convert the roman numeral to arabic processing
the symbols from left to right according to the following rules:
ERROR HANDLING REQUIREMENTS
In each of the error conditions below, display the given message and skip the numeral and continue processing the next line.
"Invalid character in input. Valid characters are I,V,X,L,C,D,M."
Submit a printout of executing your program
using
this acceptance test data.
Spring 2008: Submission instructions will be provided in class.
The numerals that represent numbers beginning with a '5' (V, L and D) may only appear once in each Roman numeral. This rule permits XVI but not VIV.
A single letter may be repeated up to three times consecutively with each occurrence of the value being additive. This means that I is one, II means two and III is three. However, IIII is incorrect for four.
Larger numerals must be placed to the left of the smaller numerals to continue the additive combination. So VI equals six and MDCLXI is 1,661.
A small-value numeral may be placed to the left of a larger value. Where this occurs, for example IX, the smaller numeral is subtracted from the larger. This means that IX is nine and IV is four. The subtracted digit must be at least one tenth of the value of the larger numeral and must be either I, X or C. Accordingly, ninety-nine is not IC but rather XCIX. The XC part represents ninety and the IX adds the nine. In addition, once a value has been subtracted from another, no further numeral or pair may match or exceed the subtracted value. This disallows values such as MCMD or CMC.
The fourth rule compares the size of value of each the numeral as
read from left to right. The value must never increase from one
letter
to the next. Where there is a subtractive numeral, this rule
applies
to the combined value of the two numerals involved in the subtraction
when compared to the previous letter. This means that XIX is
acceptable but XIM and IIV are not.