杭电1201 18岁生日
我知道,在许多人看来这是一道简单题,但说实话,这道题确实费了不少时间和精力!提交了很多次,补充了很多的知识点,比如尝试着去用随机数创建测试数据,用gdb调试,学着用文件输入输出,然后用dos比对文件的不同!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int isrui( int y ) 5 { 6 if( !(y%100) ) 7 { 8 if( !(y%400) ) 9 return 1; 10 } 11 else if( !(y%4) ) 12 return 1; 13 return 0; 14 } 15 16 int main(int argc, char *argv[]) 17 { 18 int t, y, m, d, sum, i; 19 scanf( "%d", &t ); 20 while( t-- ) 21 { 22 scanf( "%d-%d-%d", &y,&m,&d ); 23 if( (!isrui(y))&&(!isrui(y+18)) ) 24 sum = 365; 25 else if( (!isrui(y))&&(isrui(y+18)) ) 26 { 27 if( m > 2 ) 28 sum = 366; 29 else 30 sum = 365; 31 } 32 else if( (isrui(y))&&(!isrui(y+18)) ) 33 { 34 if( m > 2 ) 35 sum = 365; 36 else if( (m<=2)&&(d<=28) ) 37 sum = 366; 38 else 39 sum = -1; 40 } 41 for( i = 1; i < 18; i++ ) 42 if( sum != -1 ) 43 if( isrui(y+i) ) 44 sum += 366; 45 else 46 sum += 365; 47 printf( "%d\n", sum ); 48 } 49 return 0; 50 }