题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
写的和shit一样
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int year = scan.nextInt();
int month = scan.nextInt();
int day = scan.nextInt();
int count = 0;
int y = 0;
int[] n =new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
if(year%400 == 0 || year%4 ==0 && year%100 != 0){
y++;
}
for(int i = 0; i<month-1; i++){
count += n[i];
}
count += day;
if(y == 1 && month>2 || y == 1 && month == 2 && day == 29){
System.out.println(count+1);
}
else{
System.out.println(count);
}
}
}
}