Title:
Given an integer, convert it to a Roman numeral.
Input is guaranteed to being within the range from 1 to 3999.
Translation:
Give an integer and convert it to a Roman digital output.
This question is a simple character conversion problem. Just know what the Roman numerals mean.
There are only 1,5,10 in Roman numerals. Between 1 and 3 with a repeating 1, 4 with the IV 90 with XC and so on.
I = 1;
V = 5;
X = ten;
L = +;
C = +;
D = $;
M = +;
Code:
public static string Inttoroman (int num) {string str = ""; String roman[]={"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};int number[] = { 1000,900,500,400,100,90,50,40,10,9,5,4,1};for (int i = 0; num!=0; i++) {while (num >= number[i]) {num-=number[i];str+= Roman[i];}} return str;}
This problem is quite simple. Just know what the Roman numerals mean.
Leetcode integer to Roman integers to Rome