hdu6102 2017"百度之星"初賽(A)1005今夕何夕(模擬)
阿新 • • 發佈:2019-02-20
今夕何夕 Accepts: 1345 Submissions: 5533
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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
直接模擬即可。。。注意一下判斷閏年。
#include <bits/stdc++.h>
char s[100];
int tst;
inline bool judge(int x){
return x%100?x%4==0:x%400==0;
}
int main(){
// freopen("a.in","r",stdin);
scanf("%d",&tst);
while(tst--){
scanf("%s",s+1);int count=0;
int x=(s[1]-'0')*1000+(s[2]-'0')*100+(s[3]-'0')*10+s[4]-'0';
if(s[6]=='0'&&s[7]=='2'&&s[9]=='2'&&s[10]=='9'){
x+=1;judge(x)?count +=2:count+=1;
while(!judge(x)||count%7!=0){x+=1;judge(x)?count+=2:count+=1;}
}
else if(s[6]=='0'&&s[7]<='2'){
judge(x)?count+=2:count+=1;x+=1;
while(count%7!=0){judge(x)?count+=2:count+=1;x+=1;}
}
else{
x+=1;judge(x)?count+=2:count+=1;
while(count%7!=0){x+=1;judge(x)?count+=2:count+=1;}
}
printf("%d\n",x);
}
return 0;
}