Integer to Roman -- LeetCode 012

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

Solution 1:

class Solution
{
public:
string intToRoman(int num)
{
     // 关键
const int radix[] = {, , , , , ,
, , , , , , };
const string symbol[] = {"M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I"}; string roman;
for(size_t i = ; num > ; ++i)
{
int count = num / radix[i];
num %= radix[i];
for(; count > ; --count) roman += symbol[i];
}
return roman;
}
};
上一篇:javaScript基础练习题-下拉框制作


下一篇:【LeetCode】Roman to Integer & Integer to Roman