怎么算哪一年的哪月哪日是星期几

2024-12-25 08:11:26
推荐回答(2个)
回答1:

看一下万年历1900|01|01是星期一,当成已知,计算要测的那一天距1900|01|01有多少天,对7求余变成0~6的数,分别对应星期一至星期日。

回答2:

#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<<"日 "<<"一 "<<"二 "<<"三 "<<"四 "<<"五 "<<"六 "<for(i=1;i<=b;i++)
cout<<" ";
e=daym(year,month);
for(i=1;i<=e;i++)
{cout<if((i+b)%7==0)cout<cout<void main()
{int year,month;
char ch;
cout<<"请输入年月";
cin>>year>>month;
while(1)
{zhixing(year,month);
cout<<"下月输入N,上月输入B"<cin>>ch;
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++的万年历