您的位置:首页 > 其它

LeetCode:Integer to Roman

2016-05-22 10:05 302 查看


Integer to Roman

Total Accepted: 64703 Total
Submissions: 165064 Difficulty: Medium

Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.

Subscribe to see which companies asked this question

Hide Tags
 Math String

Hide Similar Problems
 (E) Roman to Integer (H)
Integer to English Words

c++ code:

class Solution {
public:
string intToRoman(int num) {
string M[] = {"", "M", "MM", "MMM"};
string C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: