[LeetCode]-011-Integer_to_Roman
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的更多相关文章
- 【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). ...
- [Leetcode]011. Container With Most Water
public class Solution { public int maxArea(int[] height) { int left = 0, right = height.length - 1; ...
- leetcode python 011
####给定n个非负整数a1,a2,...,an,其中每个表示坐标(i,ai)处的点.##绘制n条垂直线,使得线i的两个端点位于(i,ai)和(i,0).##找到两条线,它们与x轴一起形成一个容器,这 ...
- Leetcode:integer_to_roman
一. 题目 将给定的数字(阿拉伯数字)转化成罗马数字. 数字不会大于3999 二. 分析 首先我们要知道神马是罗马数字,尽管听说过.但事实上我还真没有记住,于是就google了下,具体 ...
- 【LeetCode】011 Container With Most Water
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- [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 ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Restore IP Addresses 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- [LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
随机推荐
- redis之使用场景
随着数据量的增长,MySQL 已经满足不了大型互联网类应用的需求.因此,Redis 基于内存存储数据,可以极大的提高查询性能,对产品在架构上很好的补充.在某些场景下,可以充分的利用 Redis 的特性 ...
- 32-第3章 数据链路层--抓包分析数据帧格式-ISO一图了然-小结
OSI理论模型 层级 名称 事物举例 功能 数据单位 别名 数据组成 协议举例 7 应用层 QQ.OA 网络通信 上层数据 上层数据 HTTP/FTP/DNS 6 表示层 web数据压缩.https加 ...
- Laravel-admin 加载视图后,blade 模板 JS 失效
laravel-admin js无法解析 解决 在不需要使用 pjax 的地方使用 Admin::disablePjax();
- 三、使用Fiddler劫持网络资源(手机端)
一.使用说明https://www.cnblogs.com/woaixuexi9999/p/9247705.html
- PrimeFaces ab function
The PrimeFaces.ab function is a shortcut function for PrimeFaces.ajax.AjaxRequest. //ajax shortcut a ...
- js - 基础 之 预编译总结
js运行步骤 语法解析(检查有无语法错误) 预编译 解释运行(将 js 翻译成计算机识别的语言(0.1组成),翻译一行执行一行) 预编译 [全局]: 创建 GO( Grobal Object ) 对象 ...
- Codeforces Round #593 (Div. 2) C. Labs A. Stones
题目:https://codeforces.com/contest/1236/problem/A 思路:两种操作收益都是3 且都会消耗b 操作2对b消耗较小 则可优先选择操作2 再进行操作1 即可得到 ...
- oracle pl/sql 程序设计 历史笔记整理
20131016 周三 oracle pl/sql 程序设计 第2章 创建并运行pl/sql代码 sqlplus yjkhecc/yjkhecc@10.85.23.92:1521/orcl 在java ...
- BZOJ3745 / SP22343 NORMA2 - Norma 分治,CDQ分治
要命的题目. 写法:分类讨论进行计算. 枚举过每一个\(mid\)的所有区间.对于左端点\(i∈[l, mid - 1]\),向左推并计算\([l,mid]\)范围内的最大\(/\)最小值. 然后右端 ...
- CodeForces-1167C
链接: https://vjudge.net/problem/CodeForces-1167C 题意: In some social network, there are n users commun ...