直接将各个数位上每个数所代表的罗马数字表示成字符串数组,然后提取出num的各位数,将对应的string相加
class Solution { public: string intToRoman(int num) { string romanSingle[] = {"","I","II","III","IV","V","VI","VII","VIII","IX"}; string romanTen[] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}; string romanHundred[] = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}; string romanThousand[] = {"","M","MM","MMM","MMMM"}; return romanThousand[num/1000] + romanHundred[(num%1000)/100] + romanTen[(num%100)/10] + romanSingle[num%10]; } };