#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);
}
}
}
}
CCF认证201503-3节日
最新推荐文章于 2022-04-19 14:52:42 发布