#include<iostream>
#include<iomanip>
using namespace std;
int type(int m) {
if (m % 4 != 0 || (m % 100 == 0 && m % 400 != 0)) {
return 0;//不是闰年
}
else{
return 1;//是闰年
}
}
char week[7][10] = { "Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday" };
int year[2] = { 365,366 };
int month[2][12] = { {31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31} };
int main()
{
int days, dayOfWeek;
int i = 0, j = 0;
while (cin >> days && days != -1) {//这也行?!
dayOfWeek = days % 7;
for (i = 2000; days >= year[type(i)]; i++) {
days -= year[type(i)];
}
for (j = 0; days >= month[type(i)][j]; j++) {//很巧妙
days -= month[type(i)][j];
}
cout<< i << "-" << setw(2) << setfill('0') <<j + 1 << "-" << setw(2) << setfill('0') << days + 1 <<" "<<week[dayOfWeek] << endl;
}
system("pause");
}
这里的格式输出挺容易错的,
要月和日都能补0.
网友评论