Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
public int RomanToInt(string s) {
Dictionary<char,int> roman=new Dictionary<char,int>{{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
int num=0;
for(int i=0;i<s.Length;i++)
{
if(i == s.Length - 1 ||roman[s[i]] >= roman[s[i+1]])
num+=roman[s[i]];
else
num-=roman[s[i]];
}
return num;
}