1949年的国庆节(10月1日)是星期六。
今年(2012)的国庆节是星期一。
那么,从建国到现在,有几次国庆节正好是星期日呢?
只要答案,不限手段!
可以用windows日历,windows计算器,Excel公式,。。。。。
当然,也可以编程!
不要求写出具体是哪些年,只要一个数目!
千万不要提交源代码!
答案不要写在这里,写在“解答.txt”中
参考答案:
9
这题查日历貌似是最快的方法吧。编程序花的时间肯定比查日历的时间长。不过我还是编了程序检验一下。
解题思路:一天一天的加。日期加,星期加。
代码:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
bool leap(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return true;
return false;
}
int main(int argc, char *argv[]) {
int year=1949,month=10,day=1;
int th=6;//星期几
int count=0;
for(int i=1;i<=23000;i++)
{
day++;
th++;
if(th>7)
th=1;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day>31)
{
month++;
day=1;
}
}
if(month==4||month==6||month==9||month==11)
{
if(day>30)
{
month++;
day=1;
}
}
if(month==2&&leap(year))
{
if(day>29)
{
month++;
day=1;
}
}
else if(month==2&&!leap(year))
{
if(day>28)
{
month++;
day=1;
}
}
if(month>12)
{
year++;
month=1;
}
if(month==10&&day==1&&th==7)
count++;
if(year==2012)
break;
}
cout<<count<<endl;
return 0;
}