Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

题目大意:把一个整数转换成罗马数字

 public class Solution{
private String[][] arr = {
{"0","I","II","III","IV","V","VI","VII","VIII","IX"},
{"0","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
{"0","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
{"0","M","MM","MMM"}
};
public String intToRoman(int num) {
if(num<0 || num>3999)
return "";
StringBuilder res = new StringBuilder();
int tmp = num;
if((tmp/1000)!=0)
res.append(arr[3][tmp/1000]);
tmp = tmp%1000;
if((tmp/100)!=0)
res.append(arr[2][tmp/100]);
tmp = tmp%100;
if((tmp/10)!=0)
res.append(arr[1][tmp/10]);
tmp = tmp%10;
if(tmp!=0)
res.append(arr[0][tmp]);
return res.toString();
} public static void main(String[] args){
int param = 1234;
if(args.length==1){
param = Integer.valueOf(args[0]);
}
Solution solution = new Solution();
String res = solution.intToRoman(param);
System.out.println(res);
}
}

[LeetCode]-011-Integer_to_Roman的更多相关文章

  1. 【JAVA、C++】LeetCode 011 Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  2. [Leetcode]011. Container With Most Water

    public class Solution { public int maxArea(int[] height) { int left = 0, right = height.length - 1; ...

  3. leetcode python 011

    ####给定n个非负整数a1,a2,...,an,其中每个表示坐标(i,ai)处的点.##绘制n条垂直线,使得线i的两个端点位于(i,ai)和(i,0).##找到两条线,它们与x轴一起形成一个容器,这 ...

  4. Leetcode:integer_to_roman

    一.     题目 将给定的数字(阿拉伯数字)转化成罗马数字. 数字不会大于3999 二.     分析 首先我们要知道神马是罗马数字,尽管听说过.但事实上我还真没有记住,于是就google了下,具体 ...

  5. 【LeetCode】011 Container With Most Water

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  6. [LeetCode] Binary Watch 二进制表

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  7. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  8. [LeetCode] Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  9. leetcode & lintcode for bug-free

    刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...

  10. [LeetCode] Stickers to Spell Word 贴片拼单词

    We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...

随机推荐

  1. [MtOI2019]永夜的报应 题解

    题面 题面说的乱糟糟的看起来似乎是个可持久化线性基: 然而~ 一个式子搞定一切: a^b<=a+b 那么把所有数异或起来便是答案: #include <bits/stdc++.h> ...

  2. 你知道dos和cmd之间的关系以及区别吗?

    含义 dos 英文disk operation system,意思是磁盘操作系统是微软系列操作系统之一,dos是一个独立的操作系统,dos对操作人员的要求是比较高的,操作者需要记住很多的命令,并利用命 ...

  3. 枚举java语言中的修饰符组合

    package model; /*22:37 2019/7/20*/ /* top class的修饰符组合 abstract final public 2 * 2 * 2 warning: abstr ...

  4. Scala Partial Function从官方文档解析

    A partial function of type PartialFunction[A, B] is a unary function where the domain does not neces ...

  5. 3U VPX 加固智能计算异构服务器

    3U VPX 加固智能计算异构服务器 北京太速科技有限公司在线客服:QQ:448468544 公司网站:www.orihard.com联系电话:15084122580

  6. UI 设计中的渐变

    简评: 渐变是通过两种或多种不同的色彩来绘制一个元素,同时在颜色的交界处进行衰减变化的一种设计.从拟物到扁平再到渐变,人们慢慢发现它能创造出从未有过的一种色彩感觉 -- 独特.现代和清爽.(本文译者@ ...

  7. 写一个函数,对于一个给定的整数,如果它的二进制模式从正向看和反向看是一样的,那么返回true;

    写一个函数,对于一个给定的整数,如果它的二进制模式从正向看和反向看是一样的,那么返回true:也就是实现这样一个函数boolean isPalindrome(int x); 分析一下,该题目主要是通过 ...

  8. ubuntu 添加新用户并赋予root权限

    1 sudo adduser wolbo 2 sudo vim /etc/sudoers root ALL=(ALL) ALLwolbo ALL=(ALL) ALL wolbo ALL=(ALL) N ...

  9. springboot返回html和jsp

    一.返回html (1)添加maven依赖 <dependency>    <groupId>org.springframework.boot</groupId>  ...

  10. 八、asynicio模块以及爬虫应用asynicio模块(高性能爬虫)

    asynicio模块以及爬虫应用asynicio模块(高性能爬虫) 一.背景知识 爬虫的本质就是一个socket客户端与服务端的通信过程,如果我们有多个url待爬取,只用一个线程且采用串行的方式执行, ...