整数转换成罗马数字

给定一个整数 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.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String [][]str= {{"","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"}};
		String Roman="";
		Roman+=str[3][n/1000%10];
		Roman+=str[2][n/100%10];
		Roman+=str[1][n/10%10];
		Roman+=str[0][n%10];
		System.out.println(Roman);
	}
}

阅读更多
个人分类: 计蒜客练习
上一篇最后一个单词的长度
下一篇罗马数字转换成整数
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭