Leetcode12--->Integer to Roman(整数转换为罗马数字)
题目: 给定一个整数,将其转换为罗马数字;
题目很简单,主要是依靠整数和罗马数字的对应表:
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(整数转换为罗马数字)的更多相关文章
- 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 ,即为两个并 ...
- lintcode :Integer to Roman 整数转罗马数字
题目 整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 样例 4 -> IV 12 -> XII 21 -> XXI 99 -> XC ...
- [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 ...
- 【LeetCode】12. Integer to Roman 整数转罗马数字
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:roman, 罗马数字,题解,leetcode, 力扣, ...
- 【LeetCode】Integer to Roman(整数转罗马数字)
这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...
- [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 ...
- [LintCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. The number is guaranteed to be within the range fro ...
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- [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 ...
随机推荐
- 网页转PDF作为邮件附件
Nuget 引入 OpenHtmlToPdf using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.UseD ...
- JS计算24节气的方法
function getjq(yyyy,mm,dd){ mm = mm-1; var sTermInfo = new Array(0,21208,42467,63836,85337,107014,12 ...
- redis 大批量数据插入导致MISCONF Redis is configured to save RDB snapshots的解决
PS:之前写过一遍,那个方法没有彻底解决,现找到真正的解决方法 环境:redis 3.2.100 windows版(注意!!!这是关键),win10,redis客户端spring boot 2.0.7 ...
- Python+selenium之测试报告(3)
较测试报告(2),该文章将测试报告和测试截图存放在随机变动的文件夹下面,去除了要存放在指定文件夹下面的限制. 注:遇到问题有: 1.创建由时间自动拼接的多级文件夹 2. import os impor ...
- Java-Web总结03
*1 dom4j解析器 1)CRUD的含义:CreateReadUpdateDelete增删查改 2)XML解析器有二类,分别是DOM和SAX. a)DOM一次性将整个XML文件读到内存,形成 ...
- SAP C4C Opportunity和SAP ERP Sales流程的集成
首先在C4C里创建一个新的Opportunity: 给这个Opportunity添加一个新的产品: 点按钮:Request Pricing, 从ERP抓取pricing数据,点按钮之前Negotiat ...
- ECshop安装提示cls_image::gd_version() 和不支持JPEG
ecshop版本:ECShop_V2.7.3_UTF8_release1106php 版本 5.5--------------------------------------------------- ...
- Launch Instance---source for openstack
If you want to create an instance that uses ephemeral storage, meaning the instance data is lost whe ...
- wsl基本安装与配置
wsl简介: Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层.它是由微软与Canoni ...
- Codeforces 517 #A
http://codeforces.com/contest/1072/problem/A 题目挺简单,就是让你求几个环,占得方格的个数,然而题目为什么给出了公式呢? 然而给出的公式辣么丑,还是不用的好 ...