题意:起始日期为2001-1-1,求过了那天后的日期还有那天是周几。
思路:最重要的是判断闰年,加一个判断函数,之后周几对7取余数就知道了。
#include <iostream> using namespace std; int mon[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31}; int yea[2]={365,366}; int n; char zhou[7][15]={"Saturday","Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int judge(int y){ if((y%400==0)||(y%4==0&&y%100!=0)) return 1; else return 0; } int main(int argc, char** argv) { while(cin>>n&&n!=-1){ int i,j,day=1; int ff=n%7; for(i=2000;n>=yea[judge(i)];i++) n-=yea[judge(i)]; int tt=judge(i); for(j=1;n>=mon[tt][j];j++) n-=mon[tt][j]; day+=n; printf("%d-%02d-%02d %s\n",i,j,day,zhou[ff]); } return 0; }