今夕何夕
Problem Description
今天是2017年8月6日,農歷閏六月十五。
小度獨自憑欄,望著一輪圓月,發出了“今夕何夕,見此良人”的寂寞感慨。
為了排遣郁結,它決定思考一個數學問題:接下來最近的哪一年里的同一個日子,和今天的星期數一樣?比如今天是8月6日,星期日。下一個也是星期日的8月6日發生在2023年。
小貼士:在公歷中,能被4整除但不能被100整除,或能被400整除的年份即為閏年。
Input
第一行為T,表示輸入數據組數。
每組數據包含一個日期,格式為YYYY-MM-DD。
1 ≤ T ≤ 10000
YYYY ≥ 2017
日期一定是個合法的日期
Output
對每組數據輸出答案年份,題目保證答案不會超過四位數。
Sample Input
3 2017-08-06 2017-08-07 2018-01-01
Sample Output
2023 2023 2024
?————————————————————————
2月29日需要一波特判
其他的話如果月是2月29前他就會受今年是否為閏年的影響
不然就受到明年是否是閏年的影響


#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='0') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f; } int T,n,y,r,ans; char s[55]; int pd(int x){if(x%400==0) return 1;if(x%4==0&&x%100!=0) return 1;return 0; } int main() {T=read();while(T--){scanf("%d-%d-%d",&n,&y,&r);int k=0;if((y<=2&&r<29)||(y<=1)){for(int i=n+1;;i++){if(pd(i-1)) k+=2;else k++;if(k%7==0){ans=i;break;}}}else if(y>2){for(int i=n+1;;i++){if(pd(i)) k+=2;else k++;if(k%7==0){ans=i;break;}}}if(y==2&&r==29){for(int i=n+4;;i+=4){if(!pd(i)) k+=4;else k+=5;if(pd(i)&&k%7==0){ans=i;break;}}}printf("%d\n",ans);}return 0; }
?