有关日历计算,

有关日历计算,

题目
有关日历计算,
要求输入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
2004-10-17 Sunday
要c的
答案
以下是用C++写的
#include
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==mouth && p->num>=28)
{
mouth++;
p->num-=28;
}
else if(mouthnum>mouth%2+30)
{
p->num-=(mouth%2+30);
mouth++;
}
else if(mouth>=9 && p->num>(mouth+1)%2+30)
{
p->num-=((mouth+1)%2+30);
mouth++;
}
else
break;
}
day = p->num;
week = (dayTemp + year-2001+1)%7;
cout
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.