http://acm.pku.edu.cn/JudgeOnline/problem?id=2080巧妙的方法
首先要知道起始日期是星期幾
將判斷閏年的代碼抽象為函數(shù), 便于作為數(shù)組索引
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]);

}
}
