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. 插入数据库失败([Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version)

    报错信息如下: , ) 原因,read是数据库的关键字, 牢记,如果一个词是数据库的关键字,那么在写数据库语句的时候,这个词一定是蓝色的(关键字颜色)!!

  2. Python进阶编程 反射

    1.7反射 python面向对象中的反射:通过字符串的形式操作对象相关的属性.python中的一切事物都是对象(都可以使用反射) class Foo: f = '类的静态变量' def __init_ ...

  3. 剑指offer-数组中的逆序对-数组-python

    题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%1000 ...

  4. KNN-机器学习算法

    ''' Created on Sep 16, 2010 kNN: k Nearest Neighbors Input: inX: vector to compare to existing datas ...

  5. c# 模拟post登录

    使用模拟登录大致可以分为两步 一.post登录获取cookis public CookieContainer GetCookie(string url,string account,string pa ...

  6. JS作用域及域解析规则

    1.JS作用域:变量和函数作用的范围. 2.JS解析器可以分为域解析和逐行解读代码两个过程. 域解析:1.当进行域解析的时候,一旦找到var,就会提取后面的变量名,并给它赋值给undefined. 2 ...

  7. SVM支持向量机(1)

    一.SVM模型 1.函数间隔与几何间隔,哪一条线是最好的? (1)公式化问题. 分类模型:当里面的值小于0的时候就是-1,当里面的值是大于等于0的时候就是1 函数间隔:前面乘以y(i),是为了保持数值 ...

  8. Fliter设置字符编码,解决中文问题

    class EncodingFilter implements FileFilter{ private String encoding; @Override public boolean accept ...

  9. Jdbc Driver驱动和ServerTimeZone时区的的问题

    一.JDBC驱动的版本号以及名称问题 区别: com.mysql.jdbc.Driver 是 mysql-connector-java 5中的 com.mysql.cj.jdbc.Driver 是 m ...

  10. JS 一位数左边补零