hdu6112(模擬水題)
阿新 • • 發佈:2019-01-28
今夕何夕
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1278 Accepted Submission(s): 449Problem Description今天是2017年8月6日,農曆閏六月十五。 小度獨自憑欄,望著一輪圓月,發出了“今夕何夕,見此良人”的寂寞感慨。 為了排遣鬱結,它決定思考一個數學問題:接下來最近的哪一年裡的同一個日子,和今天的星期數一樣?比如今天是8月6日,星期日。下一個也是星期日的8月6日發生在2023年。 小貼士:在公曆中,能被4整除但不能被100整除,或能被400整除的年份即為閏年。
Input第一行為T,表示輸入資料組數。 每組資料包含一個日期,格式為YYYY-MM-DD。 1 ≤ T ≤ 10000 YYYY ≥ 2017 日期一定是個合法的日期
Output對每組資料輸出答案年份,題目保證答案不會超過四位數。
Sample Input3 2017-08-06 2017-08-07 2018-01-01
Sample Output 2023 2023 2024
Source 思路: 挺水的直接模擬就可以了。
#include<cstdio> #include<iostream> #include<cmath> using namespace std; int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int day,mon,year; int nday,nyear,nmon; int cnt; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d-%d-%d",&year,&mon,&day); int cnt=0; nday=day;nyear=year;nmon=mon; while(1) { if(nday==day&&nmon==mon&&nyear>year&&cnt%7==0) break; if(nyear%4==0&&nyear%100!=0||nyear%400==0) { month[2]=29; } else { month[2]=28; } nday++; cnt++; if(nday>month[nmon]) { nday%=month[nmon]; nmon+=1; if(nmon>12) { nyear+=1; nmon%=12; } } } printf("%d\n",nyear); } }