首页 > 代码库 > Integer to Roman
Integer to Roman
问题:将数字转化为罗马数字
分析:将所有的数字打表出来
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; }};
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。