题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
1949年的国庆节(10月1日)是星期六。今年(2012)的国庆节是星期一。
那么,从建国到现在,有几次国庆节正好是星期日呢?不要求写出具体是哪些年,只要一个数目!
心
运行限制
·最大运行时间: 1s·最大运行内存: 128M
public class Main {
static int[] w={0,31,28,31,30,31,30,31,31,30,31,30,31};
//t=0星期天
static int y=1949,m=10,d=1,t=6;
public static void main(String[] args) {
int ans=0;
//先判断再让日期++ 到最后一天其实已经结束循环了
while (y!=2012||m!=12||d!=31){
if ((y%4==0&&y%100!=0)||y%400==0){
w[2]=29;
}else {
w[2]=28;
}
//判断条件
if (check()){
ans++;
}
d++;
t++;
if (t==7){
t=0;
}
if (d>w[m]){
m++;
d=1;
}
if (m>12){
m=1;
y++;
}
}
System.out.println(ans);
}
public static boolean check(){
return m==10&&d==1&&t==0;
}
}