If any roman numeral having less value comes before numeral having value we have to add diff of both otherwise add actual value

int Solution::romanToInt(string A) {

unordered_map<char,int> roman;

roman[‘I’]=1;

roman[‘V’]=5;

roman[‘X’]=10;

roman[‘L’]=50;

roman[‘C’]=100;

roman[‘D’]=500;

roman[‘M’]=1000;

int sum=0;

for(int i=0;i<A.length();i++)

{

if(roman[A[i]]<roman[A[i+1]])

{

sum=sum+(roman[A[i+1]]-roman[A[i]]);

i++;

continue;

}

else

{

sum=sum+roman[A[i]];

}

}

return sum;

}