看一下万年历1900|01|01是星期一,当成已知,计算要测的那一天距1900|01|01有多少天,对7求余变成0~6的数,分别对应星期一至星期日。
#include
#include
using namespace std;
int dayy(int year)
{if((year%4==0&&year%100!=0)||year%400==0)return 366;
else return 365;}
int daym(int year,int month)
{switch(month)
{case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;break;
case 2:{if(dayy(year)==366)return 29;else return 28;break;}
case 4:case 6:case 9:case 11:return 30;break;}}
void zhixing(int year,int month)
{int b=5,d=2010,c=1,e,i;
if(year>=2010){while(year!=d){b+=dayy(d);d++;b=b%7;}}
if(year<2010){while(year!=d){b-=dayy(d);d--;b=b%7;b=b+7;}}
while(month!=c){b+=daym(year,c);c++;b=b%7;}
cout<
cout<<" ";
e=daym(year,month);
for(i=1;i<=e;i++)
{cout<
{int year,month;
char ch;
cout<<"请输入年月";
cin>>year>>month;
while(1)
{zhixing(year,month);
cout<<"下月输入N,上月输入B"<
if(ch=='N'||ch=='n'){month++;if(month>12){month-=12;year++;}}
else if(ch=='B'||ch=='b'){month--;if(month<1){month+=12;year--;}}
else cout<<"errer!";}}
c++的万年历