题目: 给定一个整数,将其转换为罗马数字;

题目很简单,主要是依靠整数和罗马数字的对应表:

I= 1;V= 5; X = 10; L = 50; C = 100; D = 500; M = 1000

代码如下:

 public class Solution {
public String intToRoman(int num) {
if(num <= 0)
return "";
String[][] RomanDict = new String[][] {
{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" },
{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
{ "", "M", "MM", "MMM", "", "", "", "", "", "", "" },
}; return RomanDict[3][num / 1000] +
RomanDict[2][num % 1000 / 100] +
RomanDict[1][num % 100 / 10] +
RomanDict[0][num % 10]; }
}

Leetcode12--->Integer to Roman(整数转换为罗马数字)的更多相关文章

  1. Leetcode12.Integer to Roman整数转罗马数字

    罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...

  2. lintcode :Integer to Roman 整数转罗马数字

    题目 整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 样例 4 -> IV 12 -> XII 21 -> XXI 99 -> XC ...

  3. [LeetCode] 12. Integer to Roman 整数转为罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  4. 【LeetCode】12. Integer to Roman 整数转罗马数字

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:roman, 罗马数字,题解,leetcode, 力扣, ...

  5. 【LeetCode】Integer to Roman(整数转罗马数字)

    这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...

  6. [leetcode]12. Integer to Roman整数转罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  7. [LintCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. The number is guaranteed to be within the range fro ...

  8. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. [LeetCode] 12. Integer to Roman 整数转化成罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

随机推荐

  1. 在CentOS上源码安装Nginx

    总步骤: wget http://nginx.org/download/nginx-1.10.1.tar.gz tar -xvf nginx-1.10.1.tar.gz cd nginx-1.10.1 ...

  2. Appium基础五:appium相关API

    1.获取信息类: 1.1 获取当前界面的组件: driver.currentActivity(); //获取当前界面的activity,可用于断言是否跳转到预期的activity 1.2 获取当前页面 ...

  3. Unity的stateMachineBehaviour

    Unity5新增的StateMachineBehaviour是对状态机的内置,确实方便了很多,这里记录它的两个问题: 1.如果正在执行的状态被打断,当前状态的OnStateExit不会被执行,该问题在 ...

  4. Windows UEFI 安装策略的一个细节

    在计算机已连接任何带Windows Boot Manager的硬盘的时候,系统自己不会创建EFI分区,而是用之前的

  5. HDU 4738 Caocao's Bridges taijan (求割边,神坑)

    神坑题.这题的坑点有1.判断连通,2.有重边,3.至少要有一个人背*** 因为有重边,tarjan的时候不能用子结点和父节点来判断是不是树边的二次访问,所以我的采用用前向星存边编号的奇偶性关系,用^1 ...

  6. Android(java)学习笔记124:利用Service在后台播放背景音乐

    1. 在android应用程序里,有一种没有UI的类(android.app.Service)——Service.简单来说,Service是一个 background process(背景程序),通过 ...

  7. Python XML 解析

    什么是 XML? XML 指可扩展标记语言(eXtensible Markup Language). XML 被设计用来传输和存储数据. XML 是一套定义语义标记的规则,这些标记将文档分成许多部件并 ...

  8. python+opencv模拟生成运动模糊核

    Mark:https://www.cnblogs.com/wyh1993/p/7118559.html 效果非常的好

  9. Problem O: 国家排序

    Problem O: 国家排序 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 405  Solved: 253[Submit][Status][Web ...

  10. python_97_类的继承2

    # 经典类与新式类差别主要体现在多继承上 #多继承是从左到有 class People():#经典类 #class People(object):#新式类 def __init__(self,name ...