问题描述:
代码如下:
/* * *Declaration:The author of <<Accelerated C++>> has wrote in the end of that book: As you look for reading materimal, keep in mind that books on the shelf do not make you a better programmer. Ultimately, the only way to improve your programming is to write programs. >这些程序来自一些ACM书籍,作者只为提高编程能力,实现书中例题或练习。如有侵权,请联系作者,作者将立即删除。 * *联系邮箱:mingxinglai#gmail.com * */ #include <stdio.h> int type(int); 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 main(int argc, char* argv[]) { 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]); } return 0; } int type( int m) { if( m % 4 != 0 || ( m % 100 == 0 && m % 400 != 0 )) return 0; else return 1; }