罗马数字转换整数
Given a number in Roman format and we have to convert it into integer/decimal format.
给定罗马格式的数字,我们必须将其转换为整数/十进制格式。
Example:
例:
Input: XIV
Output: 14
Input: XI
Output: 11
Algorithm:
算法:
roman_to_int(string roman)
roman_to_int(罗马字符串)
Step 1: Declare all Roman characters and its integer value
in a Array ( rmap[] ) where Index=’Roman_character’
Step 2: If (Length of roman) =<1
Return corresponding Array index value.
Step 3: else
Step 4: Repeat step 5 and step 6, While((i<roman.size())
Step 5: if(rmap[roman[i]]<rmap[roman[i+1]])
number+=rmap[roman[i+1]]-rm