有关日历计算,急~

来源:百度知道 编辑:UC知道 时间:2024/05/31 07:54:22
要求输入n,输出从2000.1.1开始往后n天的那一天的年月日星期。
Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.
Input

The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer -1, which should not be processed. You may assume that the resulting date won't be after the year 9999.
Output

For each test case, output one line containing the date and the day of the week in the format of "YYYY-MM-DD DayOfWeek", where "DayOfWeek" must be one of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".
Sample Input

1730
1740
1750
1751
-1

Sample Output

2004-09-26 Sunday
2004-10-06 Wednesday
2004-10-16 Saturday
2

以下是用C++写的

#include <iostream.h>

struct InNum
{
int num;
InNum *next;
};

void main()
{
int year=2000,day=1,mouth=1,dayTemp=0,week0=6,week;
InNum *head,*last,*p;
head=new InNum;
head->next=NULL;
last=head;
p=new InNum;
cin>>p->num;
p->next=NULL;
last->next=p;
last=last->next;

while(p->num>0)
{
p=new InNum;
cin>>p->num;
p->next=NULL;
last->next=p;
last=last->next;
}

p=head->next;

while(p->num>=0)
{
p->num--;
while(p->num>=365)
{
year++;
p->num-=365;
}
dayTemp=p->num;
while(p!=NULL && p->num>28)
{
if(2==mouth && 0==year%4 && p->num>=29)
{
mouth++;
p->num-=29;
}
else if(2==mou