int romanToInt(char* s) {
int n=strlen(s);
int c[26];
c['I'-'A']=1;
c['V'-'A']=5;
c['X'-'A']=10;
c['L'-'A']=50;
c['C'-'A']=100;
c['D'-'A']=500;
c['M'-'A']=1000;
int sum=0;
for(int i=0;i<n;i++){
if(i<n-1 && c[s[i]-'A']<c[s[i+1]-'A']){
sum-=c[s[i]-'A'];
}else{
sum+=c[s[i]-'A'];
}
}
return sum;
}
结果:
标签:10,13,int,sum,整数,罗马数字 From: https://www.cnblogs.com/llllmz/p/18076019