1 1988-03-07
7305
代码:
#include<stdio.h> int f[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool leap_year(int n) { if(n%4==0&&n%100!=0||n%4==0&&n%400==0) return true; else return false; } int DAY(int year,int month,int day) { int i,sum=0; for(i=1;i<month;++i) sum+=f[i]; sum+=day; if(month>2&&leap_year(year)) return sum+1; else return sum; } int main() { int T,year,month,day,i,sum; scanf("%d",&T); while(T--) { scanf("%d-%d-%d",&year,&month,&day); if(month==2&&day==29&&!leap_year(year+20)) { printf("-1\n"); continue; } sum=0; for(i=1;i<=19;++i) { if(leap_year(year+i)) sum+=366; else sum+=365; } if(leap_year(year)) sum=sum+(366-DAY(year,month,day)); else sum=sum+(365-DAY(year,month,day)); sum+=DAY(year+20,month,day); printf("%d\n",sum); } return 0; }
闰年并不都是每四年一润:【 四年一润,百年不润,四百年再润】
例:1980是闰年,1900并不是闰年
原文:http://blog.csdn.net/qq_18062811/article/details/38948027