int charToInt(char ch)
{
switch(ch)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000;
default:return 0;
}
}
int romanToInt(char* s)
{
int count = 0;
int sum = 0;
if(s==NULL)
return 0;
while(s[count]!='\0')
{
if(charToInt(s[count])<charToInt(s[count+1]))
{
sum = sum + charToInt(s[count+1]) - charToInt(s[count]);
count++;
}
else
sum = sum + charToInt(s[count]);
count++;
}
return sum;
}
---------------------
作者:bingkuoluo
来源:CSDN
原文:https://blog.csdn.net/bingkuoluo/article/details/83241160
版权声明:本文为博主原创文章,转载请附上博文链接!
网友评论