Roman to Integer
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) {
map<char,int> mp;
mp['I']=1; mp['V']=5; mp['X']=10; mp['L'] = 50;
mp['C']=100; mp['D']=500; mp['M']=1000;
int sum = mp[s[s.length()-1]];
for(int i=s.length()-2;i>=0;i--){
if(mp[s[i+1]] > mp[s[i]])
sum -= mp[s[i]];
else
sum += mp[s[i]];
}
return sum;
}
};