[leetcode 12] Inter to Roman
1 题目:
- 重复数次:一个罗马数字重复几次,就表示这个数的几倍。
- 右加左减:
- 在较大的罗马数字的右边记上较小的罗马数字,表示大数字加小数字。
- 在较大的罗马数字的左边记上较小的罗马数字,表示大数字减小数字。
- 左减的数字有限制,仅限于I、X、C。比如45不可以写成VL,只能是XLV
- 但是,左减时不可跨越一个位数。比如,99不可以用IC(
)表示,而是用XCIX(
)表示。(等同于阿拉伯数字每位数字分别表示。)
- 左减数字必须为一位,比如8写成VIII,而非IIX。
- 右加数字不可连续超过三位,比如14写成XIV,而非XIIII。(见下方“数码限制”一项。)
- 加线乘千:
- 在罗马数字的上方加上一条横线或者加上下标的Ⅿ,表示将这个数乘以1000,即是原数的1000倍。
- 同理,如果上方有两条横线,即是原数的1000000(
)倍。
public String intToRoman(int num) {
String[] M = {"","M","MM","MMM"};
String[] C = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String[] X = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String[] V = {"","I","II","III","IV","V","VI","VII","VIII","IX"}; return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + V[num%10];
}
[leetcode 12] Inter to Roman的更多相关文章
- Leetcode 12——Integer to Roman
12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...
- Leetcode 12. Integer to Roman(打表,水)
12. Integer to Roman Medium Roman numerals are represented by seven different symbols: I, V, X, L, C ...
- [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
一.题目链接:https://leetcode.com/problems/integer-to-roman/ 二.题目大意: 给定一个整数,返回它的罗马数字的形式. 三.题解: 要想做出这道题目,首先 ...
- [LeetCode] 12. 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 ...
- Java [leetcode 12] Integer to Roman
题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...
- [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 (整数转罗马数字)
题目链接: https://leetcode.com/problems/integer-to-roman/?tab=Description String M[] = {"", ...
随机推荐
- MySQL 检索数据及提高检索速度的方法
检索数据 mysql> SELECT [DISTINCT] 表名.列名,表名.列名,表名.列名 -- 使用通配符*表示所有列 DISTINCT表示返回不同的值 -> FROM 数据库名.表 ...
- Sophus libSophus.so
在编译包含Sophus的源文件的时候,出现如下错误 ../lib/libmyslam.so: undefined reference to `Sophus::SO3::SO3(double, doub ...
- 这一周~&&html+css的学习感悟
一周一周过的很快,这个礼拜的学习状态并不是很好,好像每个月都有那么几天学习状态不怎么样.不知道是懈怠了还是怎么了…… 没有辜负上周一开始的目标,4.6号之前我就糊好了篇论文交了上去,不知道结果如何,希 ...
- 【Web】Nginx配置开机启动
在添加nginx服务之后,大家会希望开机伴随启动nginx,避免手动路径输入启动: nginx官方提供了启动脚本:https://www.nginx.com/resources/wiki/start/ ...
- 【Game】2048小游戏
每个男孩都有一个游戏梦吧,本例简单讲述一款很火的游戏<2048>的制作. 本例参考地址:https://www.imooc.com/learn/76 游戏准备 1.游戏的逻辑(2048大家 ...
- java struts2 的 文件下载
jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...
- day10作业—(闭包迭代器递归)
补充:一个星号的 打散和聚合 a, b , *c = [1,2, 1,4] print( a , b , *c) #1 2 1 4 print(a, b, c) #1 2 [1, 4] *c , = ...
- oracle 大量连接导致数据库不能登录
系统遇到过几次这种问题,一个系统申请的session数过大,导致数据库进程数满,无法连接的问题. pl sql develope 报的错误是:ORA-12170:TNS:链接超时 oracle用户登录 ...
- MySQL mysqldump 数据备份
1.mysqldump 命令工具说明 参数注解: mysqldump 是采用SQL 级别的备份机制,它将数据表导成 SQL 脚本文件,在不同的 MySQL 版本之间升级时相对比较合适,这也是最常用的备 ...
- 2018.11.01 NOIP训练 树的排列(树形dp)
传送门 跟这道题差不多. 只不过是让权值小的儿子做权值大的儿子的父亲而已. 代码