2017-09-09 LeetCode_012 Integer to Roman

12. Integer to Roman

Given an integer, convert it to a roman numeral.

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


solution:

class Solution {
2
public:
3
    string intToRoman(int num) {
4
        string m[4] = {"", "M", "MM", "MMM"},
5
            c[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
6
            x[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
7
            i[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
8
        return m[num/1000]+c[(num%1000)/100]+x[(num%100)/10]+i[num%10];
9
    }
10
};








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章