Topic:
Given an integer, convert it to a Roman numeral.
Input is guaranteed to being within the range from 1 to 3999.
Test instructions
Given an integer, convert it to Roman numerals.
The topic given input is guaranteed to be between 1-3999.
Algorithm Analysis:
Refer to the blog http://www.cnblogs.com/springfor/p/3886459.html
* For the old, the rule of not being familiar with Roman numerals is a problem. is actually a few symbols, then the law is 1,4,5,9,10 and then 10 times times each cycle.
* algorithm is to give a number, greater than 1000 when the write on a m, also more than 1000, and then write a M ... Finally less than 1000, see more than 900 not? , greater than 500 not ... So the analogy.
* Roman numerals are represented in the following form:
I 1
Y Z
X 10
L 50
C 100
D 500
M 1,000
AC Code:
public class Solution {public String inttoroman (int num) { string str = ""; String [] symbol = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int [] value = {1000,900,500,400, +, 9, 5, 4, 1}; for (int. i=0;num!=0;i++) { while (num >= value[i]) { num-= value[i]; str + = Symbol[i];} } return str; }}
Copyright NOTICE: This article is the original article of Bo Master, reprint annotated source
[Leetcode][java] Integer to Roman