Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
从千位到各位,把每一位数对应的罗马数字字符串连接即可。
char* intToRoman(int num) {
char *base[4][10] ={"","I","II","III","IV","V","VI","VII","VIII","IX"
,"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"
,"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"
,"","M","MM","MMM","","","","","",""
};
char *res;
res=(char *)malloc(20*sizeof(char));
res[0]='\0';
int x=num/1000;
strcat(res,base[3][x]);
x=(num/100)%10;
strcat(res,base[2][x]);
x=(num/10)%10;
strcat(res,base[1][x]);
x=num%10;
strcat(res,base[0][x]);
return res;
}