AcWing 3214. 节日(有关日期的通解)
原题链接
中等
作者:
把这题Ac了
,
2024-11-19 11:55:12
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
int months[13] = {
0,31,28,31,30,31,30,31,31,30,31,30,31
};
int is_leap(int year){
if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1;
return 0;
}
int get_days(int year,int month){
if(month == 2) return months[month] + is_leap(year);
return months[month];
}
int main(){
int a,b,c,y1,y2;
cin >> a >> b >> c >> y1 >> y2;
int days = 0;
for(int i = 1850;i <= y2;i++){
for(int j = 1;j <= 12;j++){
if(i >= y1 && j == a){
int w = (1 + days) % 7; // +1是因为要加上1号
int cnt = 0;
for(int k = 1;k <= get_days(i,j);k++){
if(w == c - 1) cnt++;
if(cnt == b){
// 2014/05/11
printf("%04d/%02d/%02d\n",i,j,k);
break;
}
w = (w + 1) % 7;
}
if(cnt < b){
puts("none");
}
}
days += get_days(i,j);
}
}
return 0;
}