HDU 1201 18岁生日 模拟题

题目大意:给出一个日期,求出在这个日期的18年后一共经过了多少天,如果给的这个日期是闰年的2月29号,则输出-1.

解题报告:一个恶心的模拟题,要注意如果第一年是闰年的话,就要判断月份是大于2还是小于等于2,另外还要判断最后一年是不是闰年,如果是闰年,又要判断月份是不是大于2

 1 #include<cstdio>
 2 int judge(int y) {
 3     if((y%4==0&&y%100!=0)||y%400==0)
 4     return 366;
 5     else return 365;
 6 }
 7 int main() {
 8     int Y,M,D,T;
 9     scanf("%d",&T);
10     while(T--) {
11         int tot=0; 
12         scanf("%d-%d-%d",&Y,&M,&D);
13         if(judge(Y)==366&&M==2&&D==29) {
14             printf("-1\n");
15             continue;
16         }
17         tot+=judge(Y);
18         if(judge(Y)==366&&M>2)
19         tot--;
20         for(int i=Y+1;i<Y+18;++i)
21         tot+=judge(i);
22         if(judge(Y+18)==366&&M>2)
23         tot++;
24         printf("%d\n",tot);
25     }
26     return 0;
27 }
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3118017.html