#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const int MAXN = 10000 + 10;
int months[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*
HDU 1201
关键: T组测试数据, 每一组测试数据输入之前都要保证前面用到的数据没有保留
*/
bool isPlanted(int year){
return !( (year%4==0 && year%100!=0) || (year%400)==0 );
}
int main(){
int T;
scanf("%d", &T);
for(int i=0; i<T; i++){
int year, month, day;
year = month = day = 0;
scanf("%d-%d-%d", &year,&month,&day);
if( (month==2) && (day==29) && !isPlanted(year) ){
cout << -1 << endl;
continue;
}else if( !isPlanted(year) ){
months[2] = 29;
}else{
months[2] = 28;
}
/
int days=0, sum = 0; // days->生日离该年1月1日有几天, sum->18年后的生日离该年1月1日有几天
for( int m=1; m<month; m++){
days += months[m];
}
days += day;
for( int y=year; y<year+18; y++){
if( isPlanted(y) ){
sum += 365;
}else{
sum += 366;
}
}
if( isPlanted(year+18) ){
months[2] = 28;
}else {
months[2] = 29;
}
for( int m=1; m<month; m++){
sum += months[m];
}
sum += day;
cout << (sum-days) << endl;
}
return 0;
}
HDU 1201(18岁生日天数)
最新推荐文章于 2018-03-23 17:08:01 发布