Roman Numeral Converter

Programming Quality Challenge #1

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      D

1        10     100    1000                                      5     50     500

The "auxiliary" roman symbols may only appear once in each Roman numeral.  This rule permits XVI but not VIV.


Convert the roman numeral to arabic processing the symbols from left to right according to the following rules:

1. A symbol following one of greater or equal value adds to its value. (E.g., XII = 12)

2. A symbol preceding one of greater value subtracts its value.(E.g., IV = 4; XL = 40)

Additions may not increase, as you go from left to right. Thus, each symbol added must have a value equal or less than the last symbol which was added. Thus, LIIX is wrong, cause we added L, added I, subtracted I, then try to add X.
However, XIV is fine because we add X, subtract I, then add V (which is less than the last symbol added, X).

Another way to say this is the size of value of each the numeral as read from left to right 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.
It is not permitted to subtract an "auxiliary" symbol. (CML, not LM = 950; XLV not VL, = 45).

Can't do two consecutive subtractions, thus LIVX is illegal.

The subtracted digit must be at least one tenth of the value of the larger numeral.  Accordingly, ninety-nine is not IC but rather XCIX.  The XC part represents ninety and the IX adds the nine.

ERROR HANDLING REQUIREMENTS

If the input is not a valid roman numeral, display the message "Invalid numeral" and skip the numeral and continue processing the next line.

The program can handle inputs between 1 and 3999.


TESTING

Submit a printout of executing your program using this acceptance test data.