Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
把罗马数转换为整数
class Solution { public: int romanToInt(string s) { int result=0; int size=s.length(); if(size==0)return 0; map<char, int> rom2int={{'M',1000},{'D',500},{'C',100},{'L',50},{'X',10},{'V',5},{'I',1}}; for(int i=0; i<size; i++){ if(i!=size-1 && rom2int[s[i]]<rom2int[s[i+1]]){ result+=(rom2int[s[i+1]]-rom2int[s[i]]); i++; } else result+=rom2int[s[i]]; } return result; } };
LeetCode 013 Roman to Integer,布布扣,bubuko.com
原文地址:http://blog.csdn.net/harryhuang1990/article/details/25951213