标签:des style blog java color strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18281 Accepted Submission(s): 5776
解题思路:以闰年和2月29号作为分界线吧。如果她出生的那一年是闰年而且是2月29号,则判断18年后是否是闰年,若不是则输入-1;然后根据出生的那年和18岁那年的日期来做特判吧。
#include <stdio.h> int main() { int T; int year, month, day; int run, ping, sum, mark; scanf("%d", &T); while(T--) { scanf("%d-%d-%d", &year, &month, &day); run = 0; ping = 0; sum = 0; mark = 1; if(month == 2 && day == 29 && !( ( (year+18)%4 == 0 && (year+18)%100!=0 ) || (year+18)%400==0) ) { printf("-1\n"); continue; } for(int i = 1; i<=18; i++) { if( ( (year+i)%4 == 0 && (year+i)%100!=0 ) || (year+i)%400==0 ) run++; else ping++; } sum = 366*run + 365*ping; if( ( ( year%4 == 0 && year%100!=0 ) || year%400==0) && month<=2 && day<=28 ) sum++; if( ( ( (year+18)%4 == 0 && (year+18)%100!=0 ) || (year+18)%400==0) && month<=2 && day<=28) sum--; printf("%d\n", sum); } return 0; }
hdu 1201 18岁生日 (简单题),布布扣,bubuko.com
标签:des style blog java color strong
原文地址:http://www.cnblogs.com/fengxmx/p/3855399.html