Given a roman numeral, convert it to an integer.

Input is guaranteed to be within the range from 1 to 3999.

Analysis

The rules to transfer a roman to an integer can be understood using the following examples:

1 |
I == 1 II == 2 III == 3 IV == 4 V == 5 VI == 6 VII == 7 VIII == 8 IX = 9 X== 10, XI == 11, XL == 40, L == 50, LX == 60 |

So for any two Roman letters in the form: Left Right

if the left is smaller than the right, the result will be right – left.

if the left is larger or equal to the right, the result will right + left.

See this link for more examples of the roman numbers.

[Read More...]