CCF认证201503-3节日

在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <sstream>
#include <map>
#include <set>
using namespace std;
int ping[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int run[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLeapYear(int year)
{
    if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
        return true;
    return false;
}

int main()
{
    int a, b, c, y1, y2;
    cin>>a>>b>>c>>y1>>y2;
    if(c == 7)
        c = 0;
    for(int i = y1; i <= y2 ; ++i)
    {
        int cnt = 0, init = 2, tempb;   //每次遍历时一定要将b单独存为新变量处理,否则会影响之后的计算
        tempb = b;
        for(int j = 1850 ; j < i ; ++j)
        {
            if(isLeapYear(j))
            {
                cnt += 366;
            }
            else
                cnt += 365;
        }   //从1850年开始循环到目标年份
        cnt %= 7;
        init = (init + cnt) % 7;    //计算目标年份第一天是星期几
        if(isLeapYear(i))
        {
            cnt = 0;
            for(int j = 1 ; j < a; ++j)
            {
                cnt += run[j];
            }   //遍历到指定月份
            cnt %= 7;
            init = (init + cnt) % 7;//计算目标月份第一天是星期几
            int remain = run[a] - 1;
            while(init != c)
            {
                init = (init + 1) % 7;
                remain -= 1;
            }//到指定星期需要几天,同时在目标月份剩余天数中减去
            tempb -= 1; //已经找到一个指定星期,剩下的指定数目减1
            if(tempb * 7 > remain)  //如果剩下的天数小于到达指定天需要的时间,那么无法找到
                cout<<"none"<<endl;
            else
            {
                remain -= tempb * 7;    //减去到达目标位置需要的天数
                printf("%d/%02d/%02d\n", i, a, run[a] - remain);
            }
        }
        else
        {
            cnt = 0;
            for(int j = 1 ; j < a; ++j)
            {
                cnt += ping[j];
            }
            cnt %= 7;
            init = (init + cnt) % 7;
           // cout<<init<<endl;
            int remain = ping[a] - 1;
            while(init != c)
            {
                init = (init + 1) % 7;
                remain -= 1;
            }
            tempb -= 1;
            if(tempb * 7 > remain)
                cout<<"none"<<endl;
            else
            {
                remain -= tempb * 7;
                //cout<<remain<<endl;
                printf("%d/%02d/%02d\n", i, a, ping[a] - remain);
            }
        }
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值