Luxoft Singapore's engineering tooling receives configuration values written as Roman numerals. Implement a converter that returns the corresponding Arabic integer only when the input is a valid canonical Roman numeral. Return -1 for malformed, noncanonical, empty, or out-of-range input.
Implement roman_to_arabic(roman), where roman is a non-empty uppercase string containing only the symbols I, V, X, L, C, D, and M. Return an integer from 1 through 3999, or -1 when the input is invalid.
Canonical notation follows these rules:
IV, IX, XL, XC, CD, and CM.I, X, C, and M may appear at most three times consecutively.V, L, and D may not repeat.IIII, IL, VX, and IIV are invalid.def roman_to_arabic(roman):