题目链接:传送门
题意:
求从y1到y2年间每年的a月第b个星期c,存在输出日期,不存在输出"none"
题解:
打表
代码如下:
#include<bits/stdc++.h>
using namespace std;
int A[205][15][35];
int month[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}};
bool check(int year){
if((year%400==0)||((year%4==0)&&(year%100!=0)))return true;
return false;
}
void init(){
int i,j,k,leap,weekFlag;
weekFlag=1;
for (i=1850;i<=2050;i++){
leap=check(i);
for (j=1;j<=12;j++){
for (k=1;k<=month[leap][j];k++){
weekFlag++;
if(weekFlag>7)weekFlag=1;
A[i-1850][j][k]=weekFlag;
}
}
}
}
int main()
{
int i,j,a,b,c,Begin,End,cnt,leap;
memset(A,-1,sizeof(A));
init();
while(scanf("%d%d%d%d%d",&a,&b,&c,&Begin,&End)!=EOF){
for (i=Begin;i<=End;i++){
cnt=0;leap=check(i);
for (j=1;j<=month[leap][a];j++){
if(A[i-1850][a][j]==c){
cnt++;
if(cnt==b){
printf("%d/%02d/%02d\n",i,a,j);
break;
}
}
}
if(j>month[leap][a])printf("none\n");
}
}
return 0;
}