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

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

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. CF1168A Increasing by Modulo

    思路: 首先得做个转化,如果某个解法最终分别对a[i](i = 1, 2, ..., n)做了b[i](i = 1, 2, ..., n)次加1再取余的运算,那么可以等价地构造出x次(x = max( ...

  2. Redis、Memcache区别

    Redis.Memcache区别 redis单核 memcahce多核 redis支持数据持久化 redis支持的数据类型比较多 memcache 只有key->value类型 key-> ...

  3. css隐藏元素的几种方法与区别

    css隐藏元素的几种方法与区别 一:display:none;隐藏不占位 display 除了不能加入 CSS3 动画豪华大餐之外,基本效果卓越,没什么让人诟病的地方. 二:position:abso ...

  4. CF Gym 100187J Deck Shuffling (dfs判连通)

    题意:给你一堆牌,和一些洗牌机,可以改变牌的顺序,问你能不能通过洗牌机把数字为x的牌洗到第一个位置. 题解:反向建边,dfs判断连通性 #include<cstdio> #include& ...

  5. Dungeon Master的两种方法

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  6. CodePlus #4 最短路

    题目传送门 北极为什么会有企鹅啊,而且北纬91°在哪啊? 关键在建图 因为任意两个城市间都可以互相到达,再加上还有"快捷通道",光是建图就已经\(\rm{T}\)了-- 但这题给了 ...

  7. ES6 -- 模板字符串(反单引号)

    1)直接使用变量 // before var str = 'test'; console.log(str + "123"); // now var str = 'test'; co ...

  8. 洛谷 P1835 素数密度

    https://www.luogu.org/problemnew/show/P1835 对于40%,对每个数进行最大$O(\sqrt n)$的判断,因为n比较大所以超时. 想到线性筛,然而我们并不能筛 ...

  9. NOIP模拟赛 密室逃脱

    密室逃脱(maze.*) 即使czhou没有派出最强篮球阵容,机房篮球队还是暴虐了校篮球队.为了不打击校篮球队信心,czhou决定改变训练后的活动.近来,江大掌门的徒弟徒孙们纷纷事业有成,回到母校为机 ...

  10. 01windows常用命令及批处理

    1. 概述 复制内容:右键弹出快捷菜单,选择"标记(K)",然后选中所需要的内容,然后右键即可 粘贴内容:右键弹出快捷菜单,选择"粘贴(P)" 命令参数的路径: ...