We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f
int month[13][2]= {{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}};
//month数组用来表示平年和闰年的每个月的天数,第一维表示月份,第二维0表示平年,1表示闰年
string monthname[13]={
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" };
string weekday[7]={
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"};
string ouweekday[7] = {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
bool judge(int y)//判断平闰年
{
return (y%4==0&&y%100!=0)||(y%400==0);
}
int main()
{
int a,b;
string s;
int m;
while(cin>>a>>s>>b)
{
for(int i=1;i<=12;i++)
{
if(s==monthname[i])
{
m=i;
break;
}
}
int d=a+m*100+b*10000;
int date1=d<20180422?d:20180422;
int date2=d>20180422?d:20180422;
int y1=date1/10000,m1=date1%10000/100,d1=date1%100;
int y2=date2/10000,m2=date2%10000/100,d2=date2%100;
int ans=0;
while(y1month[m1][judge(y1)])//如果小日期的天数大于该月的天数,进入下一个月,月份加一,置为下月1号
{
m1++;
d1=1;
}
if(m1==13)//如果月份大于12,则进入下一年,月份置一
{
y1++;
m1=1;
}
ans++;//累计天数
}
//cout<20180422)//当题目所给时间比自己选定标准时间大时
{
cout<