学习到一种很好的处理日期的方式 #include <stdio.h> int year[2] = {365, 366}; //0 非润年 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}}; //0 非润年的月份//2000年1月1日 Saturday char week[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"}; int isRun(int y){ if((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0) ) return 1; //返回1 润年 return 0; } int main(){ int day, dayOfweek; while( scanf("%d",&day) == 1 && day != -1 ){ dayOfweek = day % 7; //day 对7 取模可以知道是周几 得先知道2000年1月1日 是周几 int i, j; for(i = 2000; day >= year[isRun(i)]; ++i){ day -= year[isRun(i)]; } for(j = 0; day >= month[isRun(i)][j]; ++j){ //i, j, k这些 别搞错 day -= month[isRun(i)][j]; } printf("%d-%02d-%02d %s/n",i, j + 1, day + 1, week[dayOfweek]); } return 0; } /* 2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday */