LeetCode:Integer to Roman
2016-05-22 10:05
302 查看
Integer to Roman
Total Accepted: 64703 TotalSubmissions: 165064 Difficulty: Medium
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question
Hide Tags
Math String
Hide Similar Problems
(E) Roman to Integer (H)
Integer to English Words
c++ code:
class Solution {
public:
string intToRoman(int num) {
string M[] = {"", "M", "MM", "MMM"};
string C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
}
};
相关文章推荐
- X3插件机制的UML图
- Programming Scala第5章 demo05 参数化类型的可变性
- 框架是什么?以ssh框架为例
- Java学习从菜鸟变大鸟之二 输入输出流(IO)
- 标题什么的都不重要了吧
- LeetCode:Intersection of Two Linked Lists
- 用卡特兰数求解对于给定序列有多少种出栈情况
- Programming Scala第5章demo04 传递变参
- 事务
- DOS中SET命令的详细用法
- N个数求和(cccc分数求和—gcd)
- Unity3D血条的制作
- 畅通工程(MST)
- LeetCode:Invert Binary Tree
- 写css的一些小技巧
- listview选中高亮,选中栏目变颜色的一种最简单办法
- 27. Remove Element
- spark ML 使用Word2Vec
- 冒泡排序——java
- 大整数类BigInteger