#K38062. Roman Numerals to Integer
Roman Numerals to Integer
Roman Numerals to Integer
Given a Roman numeral as a string, convert it to its integer value. The Roman numeral digits are I (1), V (5), X (10), L (50), C (100), D (500), and M (1000). Typically, the numerals are arranged from the greatest to the least value from left to right. However, to represent numbers like 4 and 9, a subtractive notation is used:
- I can precede V (5) and X (10) to form 4 and 9 respectively.
- X can precede L (50) and C (100) to form 40 and 90 respectively.
- C can precede D (500) and M (1000) to form 400 and 900 respectively.
Your task is to implement a function (or equivalent in your language of choice) that reads a Roman numeral from the standard input (stdin) and prints its integer conversion to the standard output (stdout).
Constraints: 1 ≤ |s| ≤ 15.
You may assume that the input is always valid and in uppercase.
inputFormat
The input consists of a single line containing a string representing a Roman numeral.
Example: LVIII
outputFormat
Output a single integer which is the integer representation of the Roman numeral.
Example: 58
III
3