2021-11-08

2021/11/8 23:17:00

本文主要是介绍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日为星期一



这篇关于2021-11-08的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程