
Problem Description:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
题目大意:
把十进制数字转化为罗马数字。
Solutions:
先找到不同的转化点,再依次转化
Code in C++:
class Solution {
public:
string intToRoman(int num) {
string res="";
int nums[13]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
string s[13]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
for(int i=0;i<=13;i++)
{
if(num>=nums[i])
{
for(int j=0;j<num/nums[i];j++)
res+=s[i];
num%=nums[i];
}
}
return res;
}
};




近期评论