注意优先看9**和4**
public class Solution {
public int romanToInt(String s) {int rst=0;
int i,n;
char[] ca=s.toCharArray();
n=s.length();
for(i=0;i<n;i++)
{
if(ca[i]=='M')
rst+=1000;
else if(i+1<n && ca[i]=='C' && ca[i+1]=='M')
{rst+=900;i++;}
else if(i+1<n && ca[i]=='C' && ca[i+1]=='D')
{rst+=400;i++;}
else if(ca[i]=='D')
rst+=500;
else if(ca[i]=='C')
rst+=100;
else if(i+1<n && ca[i]=='X' && ca[i+1]=='C')
{rst+=90;i++;}
else if(i+1<n && ca[i]=='X' && ca[i+1]=='L')
{rst+=40;i++;}
else if(ca[i]=='L')
rst+=50;
else if(ca[i]=='X')
rst+=10;
else if(i+1<n && ca[i]=='I' && ca[i+1]=='X')
{rst+=9;i++;}
else if(i+1<n && ca[i]=='I' && ca[i+1]=='V')
{rst+=4;i++;}
else if(ca[i]=='V')
rst+=5;
else if(ca[i]=='I')
rst+=1;
}
return rst;
}
}