题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
19491949 年的国庆节( 1010 月 11 日)是星期六。
今年(20122012)的国庆节是星期一。
那么,从建国到现在,有几次国庆节正好是星期日呢?
不要求写出具体是哪些年,只要一个数目!
运行限制
最大运行时间:1s
最大运行内存: 128M
源码:
package secondTest;
public class 星期几 {
static int days[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
static int year = 1949;
static int month = 10;
static int day = 1;
static int t = 6;
public static void main(String[] args) {
//1949 年的国庆节( 1010 月 11 日)是星期六。
//今年(20122012)的国庆节是星期一。
long res = 0;
while(year != 2012 || month != 12 || day != 31) {
if(year % 400 == 0 ||(year % 4 == 0 && year % 100 != 0)) {
days[2] = 29;
}else {
days[2] = 28;
}
if(check()) {
res++;
}
day++;
t++;
t = t % 7;
if(day > days[month]) {
month++;
day = 1;
}
if(month > 12) {
year++;
month = 1;
}
}
if(check()) {
res++;
}
System.out.println(res);
}
private static boolean check() {
// TODO Auto-generated method stub
int y = year;
int m = month;
int d = day;
if(month==10&&day==1&&t==0) {
return true;
}
return false;
}
}
正确答案9