链接:
13. 罗马数字转整数
题解:
class Solution {
public:int romanToInt(string s) {int result = 0;if (s.size() <= 0) {return result;}std::unordered_map<char, int> table{{'I', 1},{'V', 5},{'X', 10},{'L', 50},{'C', 100},{'D', 500},{'M', 1000}};for (int i = s.size()-1; i >= 0; --i) {if (i != s.size() && table[s[i]] < table[s[i+1]]) {result -= table[s[i]];} else {result += table[s[i]];}}return result;}
};
Roman to Integer
http://www.lintcode.com/zh-cn/problem/roman-to-integer/ http://www.jiuzhang.com/solutions/roman-to-integer/