Integer to Roman
来源:互联网 发布:java web小项目 编辑:程序博客网 时间:2024/06/05 08:10
Integer to Roman
Total Accepted: 41179 Total Submissions: 120292My SubmissionsGiven an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Show Similar Problems
class Soluclass Solution public:string intToRoman(int number) { int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; string numerals[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; string result; for (int i = 0; i < 13; i++) { while (number >= values[i]) { number -= values[i]; result.append(numerals[i]); } } return result; }};
</pre><pre name="code" class="cpp">
罗马数字规则:
1, 罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。
罗马数字中没有“0”。
2, 重复次数:一个罗马数字最多重复3次。
3, 右加左减:
在较大的罗马数字的右边记上较小的罗马数字,表示大数字加小数字。
在较大的罗马数字的左边记上较小的罗马数字,表示大数字减小数字。
4, 左减的数字有限制,仅限于I、X、C,且放在大数的左边只能用一个。
(*) V 和 X 左边的小数字只能用Ⅰ。
(*) L 和 C 左边的小数字只能用X。
(*) D 和 M 左 边的小数字只能用C。
0 0
- Integer to Roman & Roman to Integer
- Integer to Roman & Roman to Integer
- LeetCode Roman to Integer && Integer to Roman
- 【leetcode】Roman to Integer | Integer to Roman
- Leetcode - "Roman to Integer" & "Integer to Roman"
- LeetCode:Roman to Integer,Integer to Roman
- Integer to Roman and Roman to Integer
- LeetCode Integer to Roman & Roman to Integer
- Roman to Integer/Integer to Roman
- leetcode - roman to integer & integer to roman
- "Roman to Integer" and "Integer to Roman"
- Roman to Integer &&Integer to Roman
- Roman to Integer and Integer to Roman
- Roman to Integer/Integer to Roman
- LeetCode:Roman to Integer
- LeetCode: Integer to Roman
- LeetCode: Roman to Integer
- LeetCode Integer to Roman
- python的全局变量和局部变量
- java接口与抽象类的区别总结
- Uva-816 - Abbott's Revenge
- MyBatis批量操作报错:Parameter 'xxxList' not found. Available parameters are [list]
- UITableViewCell自定义和重用
- Integer to Roman
- Eclipse和PyDev搭建完美Python开发环境(Windows+Mac篇)
- sharepoint 2016 学习系列篇(2)-如何部署sharepoint server 2016(1)-AD域服务器安装和部署
- Python 简单串口收发GUI界面
- android Intent 实现跳转 通过注册表
- ActionContext和ServletActionContext
- Android控件CheckBox学习
- 探索 ConcurrentHashMap 高并发性的实现机制
- BeautifulSoup4 and lxml notes