月份口诀巧记:
一三五七八十腊(12月),
三十一天永不差;
四六九冬(11月)三十日;
平年二月二十八,闰年二月把一加。
1 3 5 7 8 10 12 —> 31天
4 6 9 11 —> 30天
2 –>28(平)/29(润)
按月枚举
【思路】
枚举每一年每一月的13号是从1900年1月1日开始的第几天。
import java.io.*;
class Main{
static int [] cnt = new int[7];
//除第一年的1月份是加13(再特判) 其他月份的13号都是加上前一个月的天数
//依次为1月到12月所需加的天数
static int days[] ={31,31,0,31,30,31,30,31,31,30,31,30};
public static int isRun(int y){
if( (y % 4 == 0 && y % 100 !=0)||( y % 400 == 0) )return 29;
else return 28 ;
}
public static void solve(int n){
//计算每个月的13号是从1900年1月1日开始算起的第几天
int res = 0;
for(int y = 0; y < n; y++){
for(int m = 1; m <= 12; m++){
if( y==0 && m == 1) res += 13; //第一年的第一个月
else if( m == 3 ) res += isRun(1900+y); //2月特判
else res += days[ m-1 ];
cnt [ res%7 ] ++;
}
}
}
public static void main(String args[]) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(bf.readLine());
//cnt 存储顺序是:星期天 星期一 星期二……星期六
solve(N);
for(int i = 6, j = 0 ; j < 7; i = (i+1)%7,j++)
System.out.print(cnt[i]+" ");
// 关闭输入流
bf.close();
}
}
isRun也太秀了。。
haha 英文不够 拼音来凑