标签:style blog color io ar for div sp log
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
思路:
1 class Solution { 2 public: 3 string intToRoman( int num ) { 4 char map[3][10][5] = { 5 { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }, 6 { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" }, 7 { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" }, 8 }; 9 string roman( num/1000, ‘M‘ ); 10 num %= 1000; 11 for( int i = 2, div = 100; i >= 0; --i, div /= 10 ) { 12 roman += map[i][num/div]; 13 num %= div; 14 } 15 return roman; 16 } 17 };
标签:style blog color io ar for div sp log
原文地址:http://www.cnblogs.com/moderate-fish/p/3960472.html