12 Integer to Roman(int转罗马数字Medium)

题目意思:1-3999转罗马数字

思路:从大往小减

  ps:这题有点蛋疼

 1 class Solution {
 2 public:
 3     string intToRoman(int num) {
 4         string a[]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
 5         int b[]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
 6         string str="";
 7         for(int i=12;i>=0;--i){
 8             while(num>=b[i]){
 9                 str+=a[i];
10                 num=num-b[i];
11             }
12         }
13         return str;
14     }
15 };

 

posted @ 2015-06-17 20:37  影翕  阅读(195)  评论(0编辑  收藏  举报