字典翻译 问答 其它 【有关日历计算,要求输入n,输出从2000.1.1开始往后n天的那一天的年月日星期.GiventhenumberofdaysthathaveelapsedsinceJanuary1,2000A.D,yourmissionistofindthedateandthedayoftheweek.InputTheinputconsistsofl】
问题标题:
【有关日历计算,要求输入n,输出从2000.1.1开始往后n天的那一天的年月日星期.GiventhenumberofdaysthathaveelapsedsinceJanuary1,2000A.D,yourmissionistofindthedateandthedayoftheweek.InputTheinputconsistsofl】
问题描述:

有关日历计算,

要求输入n,输出从2000.1.1开始往后n天的那一天的年月日星期.

GiventhenumberofdaysthathaveelapsedsinceJanuary1,2000A.D,yourmissionistofindthedateandthedayoftheweek.

Input

Theinputconsistsoflineseachcontainingapositiveinteger,whichisthenumberofdaysthathaveelapsedsinceJanuary1,2000A.D.Thelastlinecontainsaninteger-1,whichshouldnotbeprocessed.Youmayassumethattheresultingdatewon'tbeaftertheyear9999.

Output

Foreachtestcase,outputonelinecontainingthedateandthedayoftheweekintheformatof"YYYY-MM-DDDayOfWeek",where"DayOfWeek"mustbeoneof"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"and"Saturday".

SampleInput

1730

1740

1750

1751

-1

SampleOutput

2004-09-26Sunday

2004-10-06Wednesday

2004-10-16Saturday

2004-10-17Sunday

要c的

贾方回答:
  以下是用C++写的   #include   structInNum   {   intnum;   InNum*next;   };   voidmain()   {   intyear=2000,day=1,mouth=1,dayTemp=0,week0=6,week;   InNum*head,*last,*p;   head=newInNum;   head->next=NULL;   last=head;   p=newInNum;   cin>>p->num;   p->next=NULL;   last->next=p;   last=last->next;   while(p->num>0)   {   p=newInNum;   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;   }   elseif(2==mouth&&p->num>=28)   {   mouth++;   p->num-=28;   }   elseif(mouthnum>mouth%2+30)   {   p->num-=(mouth%2+30);   mouth++;   }   elseif(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
点击显示
其它推荐
热门其它推荐
  • 其它