12. Integer to Roman
来源:互联网 发布:科怡软件 编辑:程序博客网 时间:2024/05/17 08:26
题目:Integer to Roman
原题链接:https://leetcode.com/problems/integer-to-roman/
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
给出一个整数(1到3999,闭区间),返回它的罗马数字表示法。
这题可以和这条一起看:http://blog.csdn.net/gcs6564157/article/details/51980430
关于罗马数字的表示法就不再说了。
这题很简单,把所有的千位,百位,十位,各位都用罗马数字表示出来,然后判断数字需要几个千几个百几个十以及个位就行了。
代码如下:
class Solution {public: string intToRoman(int num) { string th[] = {"", "M", "MM", "MMM"}; string hu[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; string te[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; string ge[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; string ans; ans += th[num / 1000]; ans += hu[num % 1000 / 100]; ans += te[num % 100 / 10]; ans += ge[num %10]; return ans; }};
0 0
- 12.Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- android studio jason文件解析基础
- LeetCode 179 Largest Number
- Qt5.7.0的安装下载(windows)
- 【codeforce】Spongebob and Joke
- 在eclipse中安装python的插件
- 12. Integer to Roman
- Xcode 7 创建新项目发送请求时报错
- 关于text-decoration去掉下划线
- 在QMainWindow添加控件,无法显示问题
- epoll详解
- 大话设计模式10----模板方法模式
- Struts2的标签之通用标签
- Couldn't load hyphenate_av from loader dalvik.system.PathClassLoader
- 盘点国内外十大免费CDN网站加速服务