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

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

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. 使用Calendar来获取当前日期和时间

    1 package com.java.test; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Calendar; 5 6 pub ...

  2. android中常见的设计模式有哪些?

    建造者模式 建造者模式最明显的标志就是Build类,而在Android中最常用的就是Dialog的构建,Notification的构建也是标准的建造者模式. 建造者模式很好理解,如果一个类的构造需要很 ...

  3. Android商城开发系列(二)——App启动欢迎页面制作

    商城APP一般都会在应用启动时有一个欢迎界面,下面我们来实现一个最简单的欢迎页开发:就是打开商城App,先出现欢迎界面,停留几秒钟,自动进入应用程序的主界面. 首先先定义WelcomeActivity ...

  4. 火狐浏览器不支持location.reload()(以改变页面大小时重新刷新页面为例)

    背景:当页面大小改变时需要重新刷新页面,以适应相应的尺寸 解决方法: var url = window.location.href; var parm = parseInt(Math.random() ...

  5. java 自定义容器,实现foreach

    import java.util.Arrays; import java.util.Iterator; public class ArrayList implements Iterable<In ...

  6. C#语言命名的9种规范

    下面介绍C#语言命名的9种规范: a) 类 [规则1-1]使用Pascal规则命名类名,即首字母要大写. [规则1-2]使用能够反映类功能的名词或名词短语命名类. [规则1-3]不要使用“I”.“C” ...

  7. GTA5(侠盗猎车5)中文版破解版

    )中文版破解版迅雷下载地址(使用迅雷新建任务填上地址): magnet:?xt=urn:btih:65F16B126D8A656E4FC825DE204EBFAF04B070FC

  8. 计算机应用第三次作业:自动开机自动关机 常用DOS命令 关于文件文件夹

    一.自动开机 台式机启动时按住DEL键 进入一个蓝色的界面,界面上是英文提示 这个界面是BIOS  ,是在机器的ROM中存储 二.自动关机 自动重启 方法一在120秒钟后自动关机 win+r (RUN ...

  9. [51nod] 1301 集合异或和

    考虑不限制xor{Y}>xor{X} 考虑n=m的情况,每个数i∈[1,n]可以被分配到X集合或Y集合,或不分配 设f[S]表示{X} xor {Y} == S的方案数 有f[S]+=2*f[S ...

  10. (73)zabbix用户认证方式 内建、HTTP Basic、LDAP

    公司大大小小众多系统,不同系统不同的账号密码,管理上相当复杂,后来慢慢出现了SSO等账号统一验证,其他zabbix也提供了类似的方法,或许有些公司便可以使用公司提供的账号来登录zabbix了. zab ...