12、Integer to Roman
来源:互联网 发布:淘宝怎么增加流量 编辑:程序博客网 时间:2024/04/28 19:10
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
class Solution {public: string intToRoman(int num) { int numtt[4] = {0}; int index = 0; char numeral[4][2] = {'I', 'V', 'X', 'L', 'C','D', 'M', 'M'}; while (num) { numtt[index++] = num % 10; num /= 10; } //此题主要是弄清楚罗马数字怎么表示数字 string str; while (index--) { if (numtt[index] < 4) { while (numtt[index]--) str.push_back(numeral[index][0]); } else if (numtt[index] == 4) { str.push_back(numeral[index][0]); str.push_back(numeral[index][1]); } else if (numtt[index] < 9) { str.push_back(numeral[index][1]); while (numtt[index] > 5) { str.push_back(numeral[index][0]); --numtt[index]; } } else { str.push_back(numeral[index][0]); str.push_back(numeral[index+1][0]); } } return str; }};
0 0
- 12、Integer to Roman
- 12、Integer to Roman
- 12Integer 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
- Leetcode[12-13] Roman to Integer & Integer to Roman(Java)
- LeetCode_OJ【12】【13】Integer to Roman && Roman to Integer
- <LeetCode OJ> 13 / 12 Roman to Integer & Integer to Roman
- leetcode 12|13. Integer to Roman && Roman to Integer
- [LeetCode 12] Integer to Roman
- leetcode 12 Integer to Roman
- [leetcode 12] Integer to Roman
- [Leetcode] 12 - Integer to Roman
- [LeetCode] 015. 3Sum (Medium) (C++/Java/Python)
- UITableView的静态表格的注意事项
- Admob(6.12.x)符号未定义错误的解决方法(IOS)
- Smallest Difference (poj 2718 暴力枚举)
- C#打印九九乘法表
- 12、Integer to Roman
- 备忘:linux去bom头
- ZipAlign对apk进行优化
- android最新源代码的编译及运行(android版本5.0.1r,编译系统ubuntu14.10 x64)
- Android Intent Action 大全
- VB 关闭窗口,关闭当前窗体
- 【Jason's_ACM_解题报告】Unidirectional TSP
- php composer 在laravel中自动加载autoload_class.php中的配置
- java 容器 类