大致题意:给出自从2000 1 1过的天数,以-1结束,输出日期和星期
//以后遇到闰年的问题,坚决用二维数组
#include<stdio.h>
#include<string.h>
#define N 10010
char date[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int vis[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}; //vis[0]表示非闰
int leap[N];
void isleap()
{
int i,j;
memset(leap,0,sizeof(leap));
for(i=2000;i<N;i++)
if(i%4==0&&i%100!=0||i%400==0)
leap[i]=1;
}
int main()
{
int i,j,k;
int num;
int flag;//星期代表元
int year;
isleap();
while(scanf("%d",&num),num!=-1)
{
k=num;
flag=(num+6)%7;//第一天星期6,先求flag是因为,后来num要改变
for(i=2000;num>=(leap[i]==1?366:365);i++)//第一次判断便不成立时,i没有自增,以后就自增了
{
if(leap[i])
num-=366;
else
num-=365;
}
// printf("i=%d\n",i);
for(j=0;num>=vis[leap[i]][j]&&j<12;j++)//月份
{
num-=vis[leap[i]][j];
}
printf("%d-%02d-%02d %s\n",i,j+1,num+1,date[flag]);//注意6要输出为06
}
return 0;
}