题目
将给定的数字转换成罗马数字
代码
function convert(num) {
var arr= [["","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"]];
var a,b;
var index = 0;
var roman = "";
while(num !== 0) {
a = num % 10;
num = Math.floor(num / 10);
b = arr[index][a];
roman = b + roman;
index++;
}
return roman;
}
convert(999);