分析
从00年遍历到20年,通过ans计数,遇到特殊日期,ans再次++;要注意判断闰年和平年
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//day[0]表示平年的每个月天数,day[1]表示闰年的每个月天数
int[][] day = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int ans = 0;
int week = 6;//当前开始日期为周六,表示星期几
for (int i = 2000; i <= 2020; i++) {
//判断当前为闰年、平年
int year;
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
year = 1;//闰年
else
year = 0;
for (int month = 0; month < 12; month++) {//遍历这i年的每个月
for (int j = 0; j < day[year][month]; j++) {//遍历month月的所有天
if (i == 2020 && month == 9) {//到2020年10 月 1 日,需要结束
System.out.println(ans + 2);//加上10月1日的月初
return;
}
if (week == 8)//该星期一了
week = 1;
ans++;//一天一千米
//特殊的周一/月初
if (week == 1 || j == 0)//j==0就是月初
ans++;
week++;
}
}
}
}
}