class Solution {
public:
int romanToInt(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
map<char,int> m;
m['I'] = 1;
m['V'] = 5;
m['X'] = 10;
m['L'] = 50;
m['D'] = 500;
m['C'] = 100;
m['M'] = 1000;
int pre = 2000;
int result = 0;
for(int i = 0;i < s.length();i++)
{
if(pre < m[s[i]])
{
result = result + m[s[i]] - pre*2;
}
else
{
result = result + m[s[i]];
}
pre = m[s[i]];
}
return result;
}
};