#include "stdafx.h"
#include "windows.h"
#include "iostream"
#include "math.h"
using namespace std;
int leapyear(int y){
if(y%4==0&&y%100!=0||y%400==0)
return 1;
return 0;
}
int whatday(int y,int month){
int xq,w,a;
int year;
int b,s,p;
b=0;
s=0;
p=0;
for(year=1;year<=y;year++){
if(y%4==0&&y%100!=0||y%400==0){
s+=366;
}
for(w=1;w<=y;w++){
if(y%4!=0){
b+=365;}
}}
p=b+s;
xq=p%7;
return xq;
}
int _tmain(int argc, _TCHAR* argv[])
{int y,m,xq;
cin>>y>>m;
xq=whatday(y,m);
cout<<y<<"年"<<m<<"月一日是星期";
if(xq==0){
cout<<"日"<<endl;
}
else{
cout<<xq<<endl;
}
system("pause");
return 0;
}
leapyear是计算这一年是否为闰年
for(year=1;year<=y;year++){
if(y%4==0&&y%100!=0||y%400==0){
s+=366;
}
for(w=1;w<=y;w++){
if(y%4!=0){
b+=365;}
}}
这里搞了个双重循环,肯定是不行啊。
for(year=1;year<=y;year++){
if(y%4==0&&y%100!=0||y%400==0){
s+=366;
}
else
s+=365;
}}
xq = s%7;
这样就对了吗?第一年第一天确定是星期一?