LeetCode 12. Integer to Roman
很简单。直接打表。
emm但是似乎大部分人认真找规律写的代码...
class Solution { public: string intToRoman(int num) { int a[4]={0}; char s[4][10][6]={{"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}, {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, {"","M","MM","MMM"}}; int i=-1; string ans; while(num>0){ a[++i]=num%10; num/=10; } for (int i=3;i>=0;i--) ans+=string(s[i][a[i]]); return ans; } };