题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1201
题目解析:细心
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<cstdlib>
using namespace std;
int leap(int n){
if(n%100!=0&&n%4==0||n%400==0)
return 1;
return 0;
}
int main(){
int n,i,j,k,m,sum,y,d,sum1;
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%d-%d-%d",&y,&m,&d);
if(leap(y)&&m==2&&d==29){
if(!leap(y+18))
cout<<-1<<endl;
}
else{
sum=0;sum1=0;
for(j=y;j<y+18;j++){
if(leap(j))
sum+=366;
else sum+=365;
}
if(leap(y)&&m>2&&!leap(y+18)) sum--;
else if(!leap(y)&&leap(y+18)&&m>2) sum++;
cout<<sum<<endl;
}
}
}
return 0;
}