12. Integer to Roman
来源:互联网 发布:medusa 软件 编辑:程序博客网 时间:2024/05/23 02:19
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question
迭代可解
public class Solution { private int[] val = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; private String[] syb = new String[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; public String intToRoman(int num) { StringBuilder roman = new StringBuilder(); int i = 0, k; while (num > 0) { k = num / val[i]; while (k-- > 0) { roman.append(syb[i]); num -= val[i]; } i++; } return roman.toString(); }}
0 0
- 12.Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 12. Integer to Roman
- 专题一 · 1000
- weblogic中删除自动部署项目
- 一个转子曲线面积问题及其反问题的解答
- [从头学数学] 第144节 一次函数
- C# 基于SharpPcap的局域网数据包捕获 之二 监听代码
- 12. Integer to Roman
- 字符串常量存在何处
- 解决viewpager在刷新调用notifyDataSetChanged不起作用
- 3.18
- Linux基础(一)
- 根据身份证号获取星座,生肖,性别
- python学习:使用xml.dom.minidom读取xml文档内容
- QQ,微博,微信分享功能的实现
- infix2postfix