题目链接:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1175

不是我的思路,但个人觉得比较有代表性!

代码:

#include <stdio.h>

#include <string.h>
char weekday[7][20]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
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 year[2]={365,366};
int sug(int year)//判断是闰年还是平年
{
    if((year%100!=0&&year%4==0)||(year%100==0&&year%400==0))
        return  1;
    else
        return 0;
  
}
int main()
{
   int day,week,i,j;
   while(scanf("%d",&day),day+1)
   {
        week=day%7;
        for(i=2000;day>=year[sug(i)];i++)
            day-=year[sug(i)];
        for(j=0;day>=month[sug(i)][j];j++)
            day-=month[sug(i)][j];
        printf("%d-%02d-%02d %s\n",i,j+1,day+1,weekday[week]);
   }
   return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation