#include
#include
int n;
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char week[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int y, m, d;
int IsLeapYear(int year) {
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1;
return false;
}
int Run() {
++n;
int w = n;
for (int i = 2000; ; ++i) {
if (IsLeapYear(i)) {
if (n - 366 <= 0) {
y = i;
break;
}
else n -= 366;
}
else {
if (n - 365 <= 0) {
y = i;
break;
}
else n -= 365;
}
}
if (IsLeapYear(y)) month[1] = 29;
else month[1] = 28;
for (int i = 0; i < 12; ++i) {
if (n - month[i] <= 0) {
m = i + 1;
break;
}
else n -= month[i];
}
d = n;
printf("%d",y);
printf("-");
if (m < 10)
printf("0");
printf("%d",m);
printf("-");
if (d < 10)
printf("0");
printf("%d",d);
printf("%d", week[(w + 5) % 7] );
printf("\n");
return 0;
}
int main() {
scanf("%d",&n) ;
while (n != -1)
{
Run();
}
return 0;
}
你的代码想表达什么意思?保证无错吗?改成C后又有什么要求?