HDU 1201(18岁生日天数)

来源:互联网 发布:网络发展前景 编辑:程序博客网 时间:2024/05/17 04:34
#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;}

0 0
原创粉丝点击