要求将小于100的整数改写成罗马数字,具体的罗马数字怎么表达的就不详细说了,当时觉得这个题目还是很麻烦的,不过现在想想其中有规律可循的:
1 5 10 50 100 ,我们可以人为地插入 4 9 40 90 这样先求出这几个数的值将大大提高程序的性能
int ator(int n, char *buffer,sizeof(buffer)){
int GivenNum[9] = {"1","4","5","9","10","40","50","90","100"};
char Roma[9] ={"I","IV","V","IX","X","XL","L","XC","C"};
int i = 0;
while (n>0)
{
while (n >= GivenNum[i])
{
n = n - GivenNum[i];
strcat(buff,Roma[i]);
}
i = i + 1;
}
return 0;
}
受百合上一个兄弟的提醒,突然恍然大悟...哈哈~~