首页 > 代码库 > POJ - 2080 Calendar
POJ - 2080 Calendar
题意:求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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。