题目描述
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
分析:熟悉罗马数字和阿拉伯数字的转换规则,题目算法本身没有太大亮点
class Solution {
public:
string intToRoman(int num) {
string res="";
vector<int> key={1000,900,500,400,100,90,50,40,10,9,5,4,1};
vector<string> value={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
for(int i=0;i<key.size();++i){
int count=num/key[i];
for(int j=0;j<count;++j)
res+=value[i];
num=num%key[i];
}
return res;
}
};