计蒜客 - 整数转换成罗马数字

整数转换成罗马数字



  •  1000ms
  •  65536K


给定一个整数 numnum,将整数转换成罗马数字。

如 1,2,3,4,51,2,3,4,5 对应的罗马数字分别为IIIIIIIVV等,更详细的说明见此 链接。

输入格式

第一行输入一个整数 num(1 \leq num \leq 3999)num(1num3999)

输出格式

输出 numnum 对应的罗马数字。

样例输入

123

样例输出

CXXIII


/*
	由于数值很小,所以直接建立罗马数字的对应表便可,然后根据对应链接起来便可
 */

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		String [][]arr={{"","I","II","III","IV","V","VI","VII","VIII","IX"},
						{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
						{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
						{"","M","MM","MMM"}};
		
		Scanner cin = new Scanner(System.in);
		int n=cin.nextInt();
		String str="";
		str += arr[3][n/1000];
		str += arr[2][n/100%10];
		str += arr[1][n/10%10];
		str += arr[0][n%10];
		System.out.println(str);
	}
}




你可能感兴趣的:(水题,数组&字符串)