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. Two progressions CodeForces - 125D (暴力)

    大意: 给定序列, 求划分为两个非空等差序列. 暴搜, 加个记忆化剪枝. #include <iostream> #include <sstream> #include < ...

  2. PropertyUtilsBean 将bean转成map

    public static Map<String,String> beanToMap(Object bean) { Map<String,String> params =Map ...

  3. sql server 对数运算函数log(x)和log10(x)

    --LOG(x)返回x的自然对数,x相对于基数e的对数 --LOG10(x)返回x的基数为10的对数 示例:select LOG(3),LOG(6),LOG10(1),LOG10(100),LOG10 ...

  4. ELK-全文检索技术-kibana操作elasticsearch

    前言:建议kibana语法一定要学好! 1       软件安装 1.1     ES的安装 第一步:解压压缩包,放到一个没有中文没有空格的位置 第二步:修改配置文件 1.  jvm.options ...

  5. 终于明白上一篇的一顿误操作是什么了,是$,不是S !!!!!

    1,在命令行中输入export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin这样可以保证命令行命令暂时可以使用.命令执行完之后先不要关闭终端2. ...

  6. 三、使用Fiddler劫持网络资源(手机端)

    一.使用说明https://www.cnblogs.com/woaixuexi9999/p/9247705.html

  7. static静态和非静态详解

    static 作为Java中的一个关键字,用于修饰方法.成员变量(Field),统称为成员. 有static修饰的成员   属于类 1.方法称为静态方法(类方法),Field称为类的属性. 2.静态成 ...

  8. 关于PHP://input

    $data = file_get_contents("php://input");    php://input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最好 ...

  9. HTTP/1.1-HTTP/2.0-HTTP/3.0-HTTPS

    HTTP/1.1 网上关于HTTP/1.1的讨论多是基于RFC2616文档,而IETF已更新了HTTP/1.1并将其分为六个部分,使协议变得更简单易懂,对老版本RFC2616中模糊不清的部分做了解释 ...

  10. canvas在高倍屏下变模糊的处理办法

    因为canvas不是矢量图,而是像图片一样是位图模式的.如果不做Retina屏适配的话,例如二倍屏,浏览器就会以2个像素点的宽度来渲染一个像素,该canvas在Retina屏幕下相当于占据了2倍的空间 ...