ACM PKU 2080 Calendar 日期处理典型题目

ACM PKU 2080 Calendar 日期处理典型题目

http://acm.pku.edu.cn/JudgeOnline/problem?id=2080

巧妙的方法
首先要知道起始日期是星期几
将判断闰年的代码抽象为函数, 便于作为数组索引
Source Code

Problem: 
2080   User: lnmm 
Memory: 64K  Time: 625MS 
Language: C
++   Result: Accepted 

Source Code 
#include
" stdio.h "
char  week[ 7 ][ 10 ] = {"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"} ;
int  year[ 2 ] = {365,366} ;
int  month[ 2 ][ 12 ] = {31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31} ;

int  type( int  m)
{if((m%4==0&&m%100!=0)||(m%400==0))return 1;else return 0;
}

void  main()
{
    
int days,dayofweek;
    
int i=0,j=0;
    
while(scanf("%d",&days)&&days!=-1)
    
{
        dayofweek
=days%7;
        
for(i=2000;days>=year[type(i)];i++)
            days
-=year[type(i)];
        
for(j=0;days>=month[type(i)][j];j++)
            days
-=month[type(i)][j];
        printf(
"%d-%02d-%02d %s\n",i,j+1,days+1,week[dayofweek]);

    }

}

你可能感兴趣的:(ACM PKU 2080 Calendar 日期处理典型题目)