AC代码:
#include <iostream> #include <cstdio> using namespace std; int a[19]; int hanshu(long long year) { if((year%4==0&&year%100!=0)||year%400==0) return 1; else return 0; } int main(void) { freopen("in.txt","r",stdin); long long n,year; int month,day; scanf("%lld",&n); while(n--) { int i=0; int sum=0; scanf("%lld-%d-%d",&year,&month,&day); for(int j=0;j<=18;j++) a[j]=hanshu(year+j); if(a[0]==1&&a[18]==0&&month==2&&day==29) { printf("-1 "); continue; } sum+=18*365; for(int j=1;j<=17;j++) if(a[j]) sum+=1; if(a[0]==1) { if((month==2&&day<=28)||month<2) sum++; } else { if(a[18]==1) { if(month>2) sum++; } } printf("%lld ",sum); } fclose(stdin); return 0; }