题目9 打印日期
1 import java.util.Scanner; 2 3 public class Main{ 4 private static int isLeap(int year){ 5 if(year%4==0&&year%100!=0||year%400==0) return 1; 6 else return 0; 7 } 8 private static int[][] dayOfMonth={ 9 {0,0}, 10 {31,31}, 11 {28,29}, 12 {31,31}, 13 {30,30}, 14 {31,31}, 15 {30,30}, 16 {31,31}, 17 {31,31}, 18 {30,30}, 19 {31,31}, 20 {30,30}, 21 {31,31}, 22 }; 23 public static void main(String[] args) { 24 Scanner in=new Scanner(System.in); 25 while(in.hasNext()){ 26 int year=in.nextInt(); 27 int flag=isLeap(year); 28 int count=in.nextInt(); 29 int month=1; 30 31 while(count>dayOfMonth[month][flag]){ 32 count-=dayOfMonth[month][flag]; 33 month++; 34 } 35 int day=count; 36 37 String y=year+""; 38 if(y.length()==1) y="000"+y; 39 else if(y.length()==2) y="00"+y; 40 else if(y.length()==3) y="0"+y; 41 String m=month+""; 42 if(m.length()==1) m="0"+m; 43 String d=day+""; 44 if(d.length()==1) d="0"+d; 45 System.out.println(y+"-"+m+"-"+d); 46 } 47 } 48 } 49 /************************************************************** 50 Problem: 1186 51 User: 0000H 52 Language: Java 53 Result: Accepted 54 Time:930 ms 55 Memory:60392 kb 56 ****************************************************************/