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;
}
};