题解 | #Where in 和Not in#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = in.readLine(); int[] days_month = {0,31,28,31,30,31,30,31,31,30,31,30,31}; // int[] total = new int[12]; for(int i = 1;i < 13;i++){ days_month[i] += days_month[i - 1]; } String[] str1 = str.split(" "); int year = Integer.parseInt(str1[0]); int month = Integer.parseInt(str1[1]); int day = Integer.parseInt(str1[2]); int flag = 0; if(year % 4 == 0 ){ flag = 1; if(year % 100 == 0){ if(year % 400 == 0); else flag = 0; } } if(month > 2){ System.out.println(days_month[month -1] + day + flag); }else{ System.out.println(days_month[month -1] + day); }
}
}
多刷题,积蓄力量,欢迎讨论
查看9道真题和解析