您的位置:首页 > 其它

2017-09-09 LeetCode_012 Integer to Roman

2017-09-09 15:06 459 查看
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

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode