题意:求2000.1.1(周六)过n天后,是哪年哪月哪日星期几
思路:看到过好多次了这种题,细心点模拟就是了
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char w[7][10]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ,"Saturday"}; int m[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 yd[2]={365,366}; long long day; int main(){ int year,month,week; while (scanf("%lld", &day) != EOF && day!=-1){ week = (day+6)%7; year = 2000; int flag = (year%4==0 && year%100!=0)||year%400==0; ++day; while (day > yd[flag]){ day -= yd[flag]; year++; flag = (year%4==0 && year%100!=0)||year%400==0; } for (month = 1; day > m[flag][month]; month++) day -= m[flag][month]; printf("%d-%02d-%02lld %s\n",year,month,day,w[week]); } return 0; }
POJ - 2080 Calendar
时间: 2024-10-13 07:27:24