时间限制: 1 Sec 内存限制: 32 MB
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.
There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.
21 December 2012 5 January 2013
Friday Saturday
emmmm,这一题是上一题的复杂版,具体就复杂在英文的加入,需要进行英文与数字之间的转换,题目坑在连当天是几号都不知道,不过我似乎百度过,当天是2018年1月6日(似乎是某场比赛的日子??),注意在当天之前与在当天之后计算星期几的方式是不同的,详情见代码~~
#include
#include
#include
using namespace std;
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}};
char weekname[8][15]={"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
char monthname[13][15]={"","January","February","March","April","May","June","July","August","September","October","November","December"};
int StringtoNumber(char a[])
{
for(int i=1;i<13;++i)
if(strcmp(a,monthname[i])==0)
return i;
}
void NumbertoString(char a[],int ans,int flag)
{
int b;
if(flag==0)
b=6-ans%7;
else
b=(ans+6)%7;
if(b==0)
b=7;
strcat(a,weekname[b]);
}
int main()
{
char m[20],week[20];
int y1,m1,d1;
while(scanf("%d %s %d",&d1,m,&y1)!=EOF)
{
int y2=2018,m2=1,d2=6,flag=0,ans=0;
m1=StringtoNumber(m);
memset(m,'\0',sizeof(m));
memset(week,'\0',sizeof(week));
if(y1>y2||(y1==y2&&m1>m2)||(y1==y2&&m1==m2&&d1>d2))
{
flag=1;
swap(y1,y2);
swap(m1,m2);
swap(d1,d2);
}
while(y1
你可能感兴趣的:(codeup)