罗马字母规则见:https://zh.wikipedia.org/wiki/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97
因为相减减数只能是一位而且不能跨位数,相加同一个字母不能超过三个,所以可以先用一张对应表将相减能得到的数表示出来,并表述出4*10^n.
class Solution {
public:
string intToRoman(int num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string result="";
string alpha[13]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int val[13]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
for(int i=0; i<13;i++)
{
while(num>=val[i])
{
result+=alpha[i];
num-=val[i];
}
}
return result;
}
};