日期计算 节假日 一年有多少天放假

 

  先算出该年所有的星期六星期日,根据节日的日期,算出当天星期几,加相应的天数。

 

#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <string.h>

using namespace std;
int isrun(int y)//该年的天数
{
    if(y%400==0||(y%100!=0&&y%4==0))
    {
        return 366;
    }
    return 365;
}
int yue(int y,int m,int r)//几年几月几日当天星期几
{
    if(m<=2)
    {
        y--;
        m+=12;
    }
    int w=(r+2*m+3*(m+1)/5+y+y/4+y/400-y/100)%7+1;
    return w;
}
int main()
{
    int y;
    cin>>y;
    int how[4][2];
    for(int i=0;i<4;i++)
    {
        cin>>how[i][0]>>how[i][1];
    }
    int whatday;

    cin>>whatday;
    int amount=0;
    int days=isrun(y);
    if(whatday==7||whatday==6)//如果第一周已经在星期天了,就直接获得该周的星期天数
    {
        amount+=7-whatday+1;
        days-=8-whatday;
    }
    else{
            amount+=1;//计算元旦当天是否不是周六日以外的节假日
        days+=whatday-1;//如果第一周没在星期天,把该星期补全
    }
    amount+=(days/7)*2;//算出这一年星期六星期天的个数
    if(days%7==6)
    {
        amount+=1;
    }//余下的几天若为6,说明最后一星期最后一天为星期六
    int what=yue(y,5,1);//五一是星期几,不再礼拜日就加一
    if(what<6)
    {
        amount++;
    }
    what=yue(y,10,1);//十一是星期几,若小于三,加三天,若星期日或星期四,加两天,剩下的加一天
    if(what<=3)
    {
        amount+=3;
    }
    else if(what==7||what==4)
    {
        amount+=2;
    }
    else if(what==5||what==6)
    {
        amount++;
    }
    what=yue(y,12,25);
    if(what<6)
    {
        amount++;
    }
    what=yue(y,how[0][0],how[0][1]);
    if(what<=3)
    {
        amount+=3;
    }
    else  if(what==7||what==4)
    {
        amount+=2;
    }
    else if(what==5||what==6)
    {
        amount++;
    }
    for(int i=1;i<4;i++)
    {
        what=yue(y,how[i][0],how[i][1]);
        if(what<6)
    {
        amount++;
    }
    }
    cout<<amount<<endl;//输入最后的节假日
    return 0;
}

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值