#C14459. Roman Numerals Conversion
Roman Numerals Conversion
Roman Numerals Conversion
In this problem, you are given a string representing a Roman numeral. Your task is to convert the Roman numeral into its corresponding integer value. Roman numerals are represented by the following symbols:
- I = 1
- V = 5
- X = 10
- L = 50
- C = 100
- D = 500
- M = 1000
The conversion must follow the well-known rules. In particular, if a smaller numeral appears before a larger numeral it is subtracted, e.g. \(IV = 4\) and \(IX = 9\). Any numeral that does not conform to the standard Roman numeral formatting (with the maximum value being 3999) is considered invalid.
You are required to output the corresponding integer if the numeral is valid, or print Invalid Roman numeral
if the numeral is invalid.
inputFormat
The input consists of a single line containing a string roman representing the Roman numeral. The string is guaranteed to be non-empty and will contain only uppercase letters.
outputFormat
If the given Roman numeral is valid, output its corresponding integer value. Otherwise, output the string Invalid Roman numeral
.
III
3
</p>