HDU1308(平润年)

What Day Is It?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 563    Accepted Submission(s): 252


Problem Description
The calendar now in use evolved from the Romans. Julius Caesar codified a calendar system that came to be known as the Julian calendar. In this system, all months have 31 days, except for April, June, September, and November, which have 30 days, and February, which has 28 days in non-leap years, and 29 days in leap years. Also, in this system, leap years happened every four years. That is because the astronomers of ancient Rome computed the year to be 365.25 days long, so that after every four years, one needed to add an extra day to keep the calendar on track with the seasons. To do this, they added an extra day (February 29) to every year that was a multiple of four.


Julian Rule:

Every year that is a multiple of 4 is a leap year, i.e. has an extra day (February 29).

In 1582, Pope Gregory's astronomers noticed that the year was not 365.25 days long, but closer to 365.2425. Therefore, the leap year rule would be revised to the following:



Gregorian Rule:

Every year that is a multiple of 4 is a leap year, unless it is a multiple of 100 that is not a multiple of 400.

To compensate for how the seasons had shifted against the calendar up until that time, the calendar was actually shifted 10 days: the day following October 4, 1582 was declared to be October 15.


England and its empire (including the United States) didn't switch to the Gregorian calendar system until 1752, when the day following September 2 was declared to be September 14. (The delay was caused by the poor relationship between Henry VIII and the Pope.)


Write a program that converts dates in the United States using a calendar of the time and outputs weekdays.
 


 

Input
The input will be a series of positive integers greater than zero, three integers per line, which represent dates, one date per line. The format for a date is ``month day year" where month is a number between 1 (which indicates January) and 12 (which indicates December), day is a number between 1 and 31, and year is positive number.
 


 

Output
The output will be the input date and name of the weekday on which the given date falls in the format shown in the sample. An invalid date or nonexistent date for the calendar used in the United States at the time should generate an error message indicating a invalid date. The input will end with three zeroes
 


 

Sample Input
  
  
11 15 1997 1 1 2000 7 4 1998 2 11 1732 9 2 1752 9 14 1752 4 33 1997 0 0 0
 


 

Sample Output
  
  
November 15, 1997 is a Saturday January 1, 2000 is a Saturday July 4, 1998 is a Saturday February 11, 1732 is a Friday September 2, 1752 is a Wednesday September 14, 1752 is a Thursday 4/33/1997 is an invalid date.
 
 
///设计日期的最好用最朴实的方法做,注意平年闰年
#include<iostream>
#include<cstdio>
using namespace std;

int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool Is_leap(int year)
{
 if(year<=1752)
 {
 // cout<<"^"<<endl;
  if(year%4==0)
   return true;
  else return false;
 }
 else
 {
 // cout<<"+"<<endl;
  if(year%4==0&&year%100)
  {
  // cout<<"!"<<endl;
   return true;
  }
  else if(year%4==0&&year%100==0&&year%400==0)
  {
  // cout<<"&&"<<endl;
   return true;
  }
  else return false;
 }
}

int main()
{
 int mon,day,year,flag,nyear;
 int dis_day;
 int i;
 while(cin>>mon>>day>>year&&!(0==mon&&0==day&&0==year))
 {
  nyear=year;
  flag=1;
  if(mon>12||(mon!=2&&month[mon]<day)||(mon==2&&!Is_leap(year)&&month[mon]<day)||(mon==2&&Is_leap(year)&&month[mon]+1<day)||(1752==year&&mon==9&&(day>2&&day<14)))
   flag=0;
  if(flag==0)
   cout<<mon<<"/"<<day<<"/"<<year<<" is an invalid date."<<endl;
  else
  {
   dis_day=-1;
   for(i=1;i<year;i++)
    dis_day+=(Is_leap(i)==true?366:365);
   for(i=1;i<mon;i++)
    dis_day+=month[i];
   if(Is_leap(year)&&mon>2)
    dis_day++;
   dis_day+=day-1;
   if(year>1752||(year==1752&&mon>9)||(year==1752&&mon==9&&day>=14))
    dis_day-=11;
   dis_day%=7;
   switch(mon)
   {
   case 1:cout<<"January";break;
   case 2:cout<<"February";break;
   case 3:cout<<"March";break;
   case 4:cout<<"April";break;
   case 5:cout<<"May";break;
   case 6:cout<<"June";break;
   case 7:cout<<"July";break;
   case 8:cout<<"August";break;
   case 9:cout<<"September";break;
   case 10:cout<<"October";break;
   case 11:cout<<"November";break;
   case 12:cout<<"December";break;
   }
   printf(" %d, %d is a ",day,nyear);
   switch(dis_day)
   {
   case 1:cout<<"Monday"<<endl;break;
   case 2:cout<<"Tuesday"<<endl;break;
   case 3:cout<<"Wednesday"<<endl;break;
   case 4:cout<<"Thursday"<<endl;break;
   case 5:cout<<"Friday"<<endl;break;
   case 6:cout<<"Saturday"<<endl;break;
   case 0:cout<<"Sundy"<<endl;break;
   }
  }
 }
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值