poj 2846 The Bank of Kalii

poj 2846 The Bank of Kalii

历法类的题目,纯模拟,处理2月份的代码可能不是很精练,不过思路还是很清晰的
#include  < stdio.h >

int  judgeleap( int  year)
{
    
if  ( (  ! (year % 4 &&  year % 100  )  ||   ! (year % 400 ) )
        
return   1 ;
    
else   return   0 ;
}

int  leapmon[] = 0 31 29 31 30 31 30 31 31 30 31 30 31  };
int  mon[] = 0 31 28 31 30 31 30 31 31 30 31 30 31  };
int  n;

int  main()
{
    scanf(
" %d " & n);
    
for  (  int  l  =   1 ; l  <=  n; l ++  )
    {
        
int  year, day, month, inday, inmon, num, flag;
        scanf(
" %d/%d/%d%d/%d " & month,  & day,  & year,  & inmon,  & inday );
        printf(
" %d  " , l);
        
if  ( month  ==  inmon )
        {
            num
=  day - inday;
            num
= num > 0 ? num: - num;
            day
> inday ? (flag = 0 ):(flag = 1 );
        }
        
else   if  (  1   ==  month  &&   12   ==  inmon )
        {
            num
= 31 - inday + day;
            year
-- ;
            flag
=   0 ;
        }
        
else   if  (  1   ==  inmon  &&   12   ==  month )
        {
            num
= 31 - day + inday;
            year
++ ;
            flag
=   1 ;
        }
        
else   if  ( ( month  <  inmon - 1  )  ||  ( inmon  <  month - 1  ) )
        {
            num
= 8 ;
        }
        
else   if  (  2   ==  month )
        {
            
if  ( month  <  inmon )
            {
                
if  ( judgeleap(year) )
                {
                    num
= 29 - day + inday;
                    flag
=   1 ;
                }
                
else
                {
                    num
= 28 - day + inday;
                    flag
=   1 ;
                }
            }
            
else
            {
                num
= 31 - inday + day;
                flag
=   0 ;
            }
        }
        
else   if  (  2   ==  inmon )
        {
            
if  ( month  <  inmon )
            {
                num
= 31 - day + inday;
                flag
=   1 ;
            }
            
else
            {
                
if  ( judgeleap(year) )
                {
                    num
= 29 - inday + day;
                }
                
else
                {
                    num
= 28 - inday + day;
                }
                flag
=   0 ;
            }
        }
        
else   if  ( month  <  inmon )
        {
            
if  ( judgeleap(year) )
            {
                num
= leapmon[month] - day + inday;
                flag
=   1 ;
            }
            
else
            {
                num
= mon[month] - day + inday;
                flag
=   0 ;
            }
        }
        
else   if  ( inmon  <  month )
        {
            
if  ( judgeleap(year) )
            {
                num
= leapmon[month] - inday + day;
                flag
=   0 ;
            }
            
else
            {
                num
= mon[month] - inday + day;
                flag
=   1 ;
            }
        }
        
if  (  0   ==  num )
            printf(
" SAME DAY\n " );
        
else   if  (  1   ==  num )
        {
            printf(
" %d/%d/%d IS %d DAY  " , inmon, inday, year, num);
            
if  (flag) printf( " AFTER\n " );
            
else  printf( " PRIOR\n " );
        }
        
else   if  (  8   >  num)
        {
            printf(
" %d/%d/%d IS %d DAYS  " , inmon, inday, year, num);
            
if  (flag) printf( " AFTER\n " );
            
else  printf( " PRIOR\n " );
        }
        
else
            printf(
" OUT OF RANGE\n " );
    }
    
return   0 ;
}

你可能感兴趣的:(poj 2846 The Bank of Kalii)