测试链接
总时间限制: 1000ms 内存限制: 65536kB
描述
在我们现在使用的日历中, 闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年。 给定从公元2000年1月1日开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几。
输入
输入一行,每行包含一个正整数,表示从2000年1月1日开始逝去的天数。数据保证结果的年份不会超过9999。
输出
输出一行,该行包含对应的日期和星期几。格式为“YYYY-MM-DD DayOfWeek”, 其中 “DayOfWeek” 必须是下面中的一个: “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday” 或 "Saturday“。
样例输入
1
样例输出
2000-01-02 Sunday
#include<iostream>
#include<iomanip>
using namespace std;
string weeks;
int leap(int);
int month(int mon,int y){
switch(mon){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 2:return (leap(y)==366)?29:28;
default:return 30;
}
}
int leap(int year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 366;
else
return 365;
}
string week(int day)
{
switch(day%7)
{
case 1:return "Sunday";
case 2:return "Monday";
case 3:return "Tuesday";
case 4:return "Wednesday";
case 5:return "Thursday";
case 6:return "Friday";
default:return "Saturday";
}
}
void cal(int n,int &year,int &months,int &day)
{
year=2000;
while(n>=leap(year))
{
n-=leap(year);
year++;
}
months=1;
while(n>=month(months,year))
{
n-=month(months,year);
months++;
}
day=n+1;
}
int main(){
int n,chg,year,months,day;
cin>>chg;
weeks=week(chg);
cal(chg,year,months,day);
cout<<year<<"-"<<setw(2)<<setfill('0')<<months<<"-"<<setw(2)<<setfill('0')<<day<<" "<<weeks;
return 0;
}