码迷,mamicode.com
首页 > 其他好文 > 详细

Integer to Roman

时间:2014-08-01 10:32:21      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:blog   io   问题   ar   div   log   har   rom   

问题:将数字转化为罗马数字
分析:将所有的数字打表出来

class Solution {
public:
    string intToRoman(int num) {
        char c[10][10][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"}};
        int t=1;
        int tmp=num;
        string st;
        if(tmp/1000!=0) st+=c[3][tmp/1000];
        if((tmp%1000)/100!=0) st+=c[2][(tmp%1000)/100];
        if((tmp%100)/10!=0) st+=c[1][(tmp%100)/10];
        if(tmp%10!=0) st+=c[0][tmp%10];
        return st;
    }
};

  

Integer to Roman,布布扣,bubuko.com

Integer to Roman

标签:blog   io   问题   ar   div   log   har   rom   

原文地址:http://www.cnblogs.com/zsboy/p/3884175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!