2021-11-08
作者:互联网
#include<iostream>
using namespace std;
bool LeapYear(int year)
{
if((year%4==0 && year%100!=0 )||( year%400==0))
{
return 1;
}
else return 0;
}
int GetDays(int year,int month,int day)
{
bool LeapYear(int year);
int n,m,d;
n=year;
m=month;
d=day;
int b;
b=LeapYear(n);
int c1;//整年
int c2;//整月
int cy;//差:31,28
int cha;
c1=(n-1)*365;
c2=(m-1)*30;
switch((m-1))//补31
{
case 11:
case 10:
cy=4;
break;
case 9:
case 8:
cy=3;
break;
case 7:
cy=2;
break;
case 6:
case 5:
cy=1;
break;
case 4:
case 3:
cy=0;
break;
case 2:
case 1:
cy=-1;
break;
case 0:
cy=-2;
break;
}
cha=c1+c2+d+cy;
if(b==1)//ping nian
{
return cha+1;
}
else if(b==0)
{
return (cha);
}
}
/*for(y=1;y<=year-1;y++)
{
bool LeapYear(int year);
if(bool==1)
sum+=366;
else (bool==0)
sum+=365)
*/
int main ()
{
int year,month,day; int cha;
cin>>year>>month>>day;
GetDays(year,month,day);
int XINGQI=0;
int y=year%100;
int c=(year/100)-1;int m=month;
if(month==1)
{ m=13;
y--;
}
if(month==2)
{m=14;
y--;
}
int q,w,e;
q=y/4;
w=c/4;
e=26*(m+1)/10;
XINGQI=(y+q+w-2*c+e+day-2);
while (XINGQI < 0)
XINGQI += 7;
XINGQI %= 7;
if(XINGQI==0)
XINGQI=7;
cout<<"XINGQI"<<" "<<XINGQI;
return 0;
}
计算星期几,简化问题,公元1年1月1日为星期一
标签:11,case,int,08,month,break,cy,2021,year 来源: https://blog.csdn.net/m0_62207423/article/details/121218397