#C13150. Roman Numerals Conversion and Validation

    ID: 42657 Type: Default 1000ms 256MiB

Roman Numerals Conversion and Validation

Roman Numerals Conversion and Validation

You are given a Roman numeral string. Your task is to convert this Roman numeral into its corresponding integer value. However, the Roman numeral must be valid. If the numeral contains invalid characters or does not follow the standard Roman numeral rules, your program should output an appropriate error message.

The conversion must adhere to the classical rules of Roman numeral notation. For example, the numeral "III" converts to 3, "IV" converts to 4, and "MCMXCIV" converts to 1994. If the numeral is invalid (e.g., "IIII", "IC", "VV", or contains lowercase letters), an error message is produced.

If the input is an empty string, the output should be 0.

Note that any conversion error should return the error message exactly as: Error: Invalid Roman numeral for invalid characters, or Error: Invalid Roman numeral sequence for incorrectly sequenced but valid characters.

inputFormat

The input consists of a single line containing a Roman numeral string. The string may be empty.

outputFormat

Output a single line. If the Roman numeral is valid, output its integer equivalent. Otherwise, output an error message.## sample

III
3