标签:style http io ar color 使用 sp for on
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999
罗马数字计数方法:
基本字符
|
I
|
V
|
X
|
L
|
C
|
D
|
M
|
相应的阿拉伯数字表示为
|
1
|
5
|
10
|
50
|
100
|
500
|
1000
|
#include<string.h> #include<stdio.h> int ctoi(char c){ switch(c){ 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; } } int romanToInt(char *s){ int data=0; int i,j; for(i=0;s[i+1]!='\0';i++){ if(ctoi(s[i])>=ctoi(s[i+1])) data=data+ctoi(s[i]); else data=data-ctoi(s[i]); } if(s[i+1]=='\0') data=data+ctoi(s[i]); return data; } void main(){ printf("%d\n",romanToInt("XCIX")); }
标签:style http io ar color 使用 sp for on
原文地址:http://blog.csdn.net/uj_mosquito/article/details/41895177