#include <iostream>
using namespace std;
const char weak[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
int _year (int year){ //返回year年的天数
if (year % 100 == 0)
return year % 400 ? 365 : 366;
return year % 4 == 0 ? 366 : 365;
}
int _month (int month,int year){ //返回year年month月的天数
if (month == 2)
return _year (year) == 366 ? 29 : 28;
int d;
switch (month){
case 1:case 3:case 5:case 7:case 8:
case 10:case 12:
d = 31;break;
default :
d = 30;
}
return d;
}
int main (){
int n;
while (cin >> n && n!=-1){
int year=2000,month=1,day=1,wek;
wek = n % 7; //判断星期几 。
while (n){
if (n >= _year (year)){ //累加到指定的年份
n -= _year (year);
++year;
}else if (n >= _month (month,year)){ //累加到指定的月份
n -= _month (month,year);
++month;
}
else{
day += n; //日期
n = 0;
}
}
cout << year << '-' << (month<10?"0":"")<<month<<'-'<<(day<10?"0":"") << day << ' '<<weak[wek]<<endl;
}
return 0;
}
POJ 2080 (线性表)
最新推荐文章于 2017-09-24 00:06:41 发布