【LeetCode解答六】Integer to Roman问题Java解答
来源:互联网 发布:知乎英国梨和小苍兰 编辑:程序博客网 时间:2024/05/16 19:50
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
以上是题目要求
想做这道题必须要明白罗马数字是怎么写的
这样就是1-1000的表示方式,题目要求最多输入3999,所以这就够用了,可以写代码了
package Q12IntegerToRoman;import java.util.Scanner;/** * @author 单继重 * @since 2017/11/2 18:45 */public class Solution { public static String intToRoman(int num) { String str = ""; String[] strings = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; int[] values = {1,4,5,9,10,40,50,90,100,400,500,900,1000}; for (int i = 12 ; num !=0 ; i --) { while (num >= values[i]) { num -= values[i]; str += strings[i]; } } return str; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); System.out.println(intToRoman(num)); }}
阅读全文
0 0
- 【LeetCode解答六】Integer to Roman问题Java解答
- 【LeetCode解答七】Roman to Integer问题Java解答
- LeetCode OJ --问题与解答 Roman to Integer
- [Leetcode] Roman to Integer (Java)
- [Leetcode] Integer to Roman (Java)
- 【Leetcode】Roman to Integer JAVA
- [LeetCode][Java] Integer to Roman
- [LeetCode][Java] Roman to Integer
- LeetCode (Java) Roman to Integer
- 【leetcode】Roman to Integer【java】
- LeetCode : Integer to Roman [java]
- LeetCode : Roman to Integer [java]
- leetcode:Integer to Roman 【Java】
- leetcode Integer to Roman(Java)
- leetcode Roman to Integer(Java)
- [LeetCode] Roman to Integer || Integer to Roman (JAVA)
- Leetcode[12-13] Roman to Integer & Integer to Roman(Java)
- 【Leetcode】:13. Roman to Integer 问题 in JAVA
- tf.gfile的应用 来自tensorflow官网
- Packets
- (转)数据挖掘岗求职经验:腾讯+百度+华为(均拿到sp offer)
- 1599. 【GDKOI2004】香樟树
- Linux内核整体架构
- 【LeetCode解答六】Integer to Roman问题Java解答
- OpenVSwitch介绍
- android 使用adb工具抓日志,,,,抓网络包:
- 全选、反选
- springmvc中的文件上传
- C语言-计算长方形的面积
- Spark性能调优——扩展篇
- 四大组件之Service
- git/git-bash中的branch、checkout指令(git指令)