原创文章转载请注明出处
INPUT FORMAT:
OUTPUT FORMAT:
/* ID:fightin1 LANG:JAVA TASK:preface */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class preface { // 1 , 5 , 10 , 50 , 100 , 500 , 1000 static int[][] gewei = new int[][] { { 0, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0, 0 }, { 2, 0, 0, 0, 0, 0, 0 }, { 3, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0 }, { 2, 1, 0, 0, 0, 0, 0 }, { 3, 1, 0, 0, 0, 0, 0 }, { 1, 0, 1, 0, 0, 0, 0 }, }; static int[][] shiwei = new int[][] { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 2, 0, 0, 0, 0 }, { 0, 0, 3, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0 }, { 0, 0, 2, 1, 0, 0, 0 }, { 0, 0, 3, 1, 0, 0, 0 }, { 0, 0, 1, 0, 1, 0, 0 } }; static int[][] baiwei = new int[][] { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 2, 0, 0 }, { 0, 0, 0, 0, 3, 0, 0 }, { 0, 0, 0, 0, 1, 1, 0 }, { 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1, 1, 0 }, { 0, 0, 0, 0, 2, 1, 0 }, { 0, 0, 0, 0, 3, 1, 0 }, { 0, 0, 0, 0, 1, 0, 1 } };; static int[][] qianwei = new int[][] { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 0, 0, 2 }, { 0, 0, 0, 0, 0, 0, 3 } }; static char[] trans = new char[]{'I','V','X','L','C','D','M'}; public static void main(String[] args) { try { // Scanner in = new Scanner(System.in); // PrintWriter pw = new PrintWriter(System.out); Scanner in = new Scanner(new BufferedReader(new FileReader( "preface.in"))); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter( "preface.out"))); int num = in.nextInt(); int[] count = new int[7]; for (int i = 1; i <= num; i++) { // int geweishu = i % 10; // int shiweishu = i / 10; // int baiweishu = i / 100; // int qianweishu = i / 1000; int qianweishu = i /1000; int baiweishu = (i - qianweishu*1000)/100; int shiweishu = (i - qianweishu*1000 - baiweishu*100)/10; int geweishu = i % 10; for (int j = 0; j < 7; j++) { count[j] = gewei[geweishu][j] + shiwei[shiweishu][j] + baiwei[baiweishu][j] + qianwei[qianweishu][j]+count[j]; } } for (int i=0;i<7;i++){ if (count[i]!=0){ pw.println(trans[i]+" "+count[i]); } } pw.close(); } catch (Exception e) { e.printStackTrace(); } } }