#include <iostream> #include <cstdio> using namespace std; bool isLeapYear(int); int getMaxday(int ,int ); typedef struct DATE{ int year; int month; int day; void nextDay(){ day++; if(day > getMaxday(year,month)){ day = 1; month++; if(month > 12){ month = 1; year++; } } } bool operator < (const DATE &b)const{ if(year != b.year) return year < b.year; if(month != b.month) return month < b.month; if(day != b.day) return day < b.day; } bool operator !=(const DATE &b)const { return year != b.year || month != b.month || day != b.day; } }Date; //判断闰年 bool isLeapYear(int year){ return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; } //获得该年该月的最大天数 int getMaxday(int year,int month){ switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return isLeapYear(year)? 29: 28; default: return -1; } } int main(){ Date d1,d2; d1.year = 2011; d1.month = 11; d1.day = 11; while(scanf("%d%d%d",&d2.year,&d2.month,&d2.day) != EOF){ if(d2 < d1){ Date tmp = d1; d1 = d2; d2 = tmp; } int days = 0; while(d1 != d2){ d1.nextDay(); days++; } int w = 0; w= ((days + w) % 7 + 4) % 7 + 1; printf("%d\n",w); } return 0; }
原文:http://blog.csdn.net/u012027907/article/details/44906823