MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

题目地址:
         http://acm.hdu.edu.cn/showproblem.php?pid=1201
题目描述:
Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
 

Input
一个数T,后面T行每行有一个日期,格式是YYYY
-MM-DD。如我的生日是1988-03-07
 

Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出
-1
 

Sample Input
1
1988-03-07
 

Sample Output
6574

水题, 注意有没有18岁和 瑞年的判断就好了

代码如下 ( 参照奋斗哥 ) :
#include <iostream>
#include 
<cmath>
using namespace std;
bool isLeap ( int n )
{
        
return !( n % ( n % 100 ? 4 : 400 ) ); 
}
 
int main ()
{
       
int T;
    scanf ( 
"%d"&T );
       
while ( T -- )
       {
            
int year, month, day;
               scanf ( 
"%d-%d-%d"&year, &month, &day );
                  
if ( month == 2 && day == 29 )
                  {
                          cout 
<< -1 << endl;
                          
continue;
                  }
                  
int run = 0;
                  
if ( month >= 3 )
                  {
                          
for ( int i = 1; i <= 18++ i )
                             {
                       
if ( isLeap ( year + i ) )
                       {
                            run 
++;
                       }
                 }
                  }
                  
else
                  {
                          
for ( int i = 0; i < 18++ i )
                             {
                       
if ( isLeap ( year + i ) )
                       {
                                           run 
++;
                       }
                 }
                  }
                  cout 
<< 365 * 18 + run << endl;
       }
       
return 0;
}
 posted on 2010-08-18 15:50  MiYu  阅读(290)  评论(0编辑  收藏  举报