【LeetCode】12.整数转罗马数字
题目要求
解题思路
这道题最简单的方法就是枚举,因为他的范围是0——3999。因此我们使用枚举
代码实现
class Solution
{
public:
string intToRoman(int num)
{
//范围是[0,3999)
string thousand[]={"","M","MM","MMM"};
string hundred[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
string ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
string one[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
return thousand[num/1000]+hundred[num%1000/100]+ten[num%100/10]+one[num%10];
}
};