标签:
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
看了下百度百科的罗马数字。这个应该可以穷举吧
class Solution { public: string intToRoman(int num) { string c[4][10]={{"0","I","II","III","IV","V","VI","VII","VIII","IX"}, {"0","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}, {"0","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, {"0","M","MM","MMM"}}; string res = ""; if (num <= 0) { return res; } if (num / 1000 != 0) { res += c[3][num / 1000]; } if (num % 1000 / 100 != 0) { res += c[2][num % 1000 / 100]; } if (num % 100 / 10 != 0) { res += c[1][num % 100 / 10]; } if (num % 10 != 0) { res += c[0][num % 10]; } return res; } };
标签:
原文地址:http://www.cnblogs.com/SpeakSoftlyLove/p/5097138.html