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[]=0312931303130313130313031 };
int mon[]=0312831303130313130313031 };
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;
}

posted on 2011-08-11 00:36 purplest 阅读(237) 评论(0)  编辑 收藏 引用 所属分类: 模拟


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2013年3月>
242526272812
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿

随笔分类(70)

随笔档案(68)

ACMer

搜索

最新随笔

最新评论