思路:输入规定为1-3999,所以数字不会很大很复杂
直接给出每一位的数字进行组合即可,先得到num的每一位再加入字符串
class Solution {
public:
string intToRoman(int num) {
//罗马字符表
string roma[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"}
};
string res;
int i=0;
while(num>0){
res=roma[i][num%10]+res;
num/=10;
i++;
}
return res;
}
};