首页 > 其他 > 详细

12. Integer to Roman

时间:2019-12-01 16:41:31      阅读:75      评论:0      收藏:0      [点我收藏+]
 1 class Solution {
 2 public:
 3     static array<pair<int, string>, 13> romandata;
 4     string intToRoman(int num) {
 5         string res = "";
 6         for(auto it:romandata){
 7             while(num/it.first){
 8                 res += it.second;
 9                 num-=it.first;
10             }
11         }
12         return res;
13     }
14 };
15 array<pair<int, string>, 13> Solution::romandata = {{ {1000, "M"}, {900, "CM"}, 
16                                                      {500, "D"}, {400, "CD"}, {100, "C"},{90, "XC"}, 
17                                                      {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, 
18                                                      {5, "V"}, {4,"IV"}, {1, "I"} }}; 

 

12. Integer to Roman

原文:https://www.cnblogs.com/zhuangbijingdeboke/p/11966005.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!