求日期和星期,不查怎么知道2000.1.1是星期六呢
#include<cstdio> using namespace std; //2000.1.1 星期六 //暴力吧,想不出什么捷径 bool is_leapyear(int n) { return ((n%4==0&&n%100!=0)||(n%400==0)); } char week[10][10]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; int month[20] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int main() { int n; int year,m,day,w; while(scanf("%d",&n)&&n!=-1) { year = 2000,m = 1,day = 1,w = 6; w = (w+n)%7; while(n>365) { n -= 365; if(is_leapyear(year)) n--; year++; } while(n--) { if(is_leapyear(year)) month[2] = 29; else month[2] = 28; day++; if(day>month[m]) { day = 1; m++; if(m>12) { m = 1; year++; } } } printf("%d-%02d-%02d %s\n",year,m,day,week[w]); } return 0; }