输入日期,求星期,帮我查一下哪里错了,求助···
题目描述A year and the day of week of the first day in this year will be given to you, you are asked to calculate the day of week of any given date for this year.
输入
The input may contain several test cases.
The first line of each test case is a year (a 4-digit positive integer) and the day of week of the first day in this year (Sun, Mon, Tue, Wed, Thu, Fri, or Sat).
The second line is the given date of this year (in format of integer/integer, denoting Month/Day). You need to calculate the day of week of this date.
Input is terminated by EOF.
输出
For each test case, output the day of week of the given date in this year (i.e. Sun, Mon, Tue, Wed, Thu, Fri, or Sat)
样例输入
2009 Thu
12/25
1996 Mon
12/25
1984 Sun
2/2
样例输出
Fri
Wed
Thu
#include <iostream>
#include <string>
using namespace std;
int main()
{
int y;
string w;
while(cin >> y >> w)
{
int m,d,n,W;
if(w=="Sun") W=0;
else if(w=="Mom") W=1;
else if(w=="Tue") W=2;
else if(w=="Wed") W=3;
else if(w=="Thu") W=4;
else if(w=="Fri") W=5;
else if(w=="Sat") W=6;
scanf("%d/%d",&m,&d);
if(m==1) n=d%7;
else if (m==2) n=(d+31)%7;
else
{
if ((y%4==0&&y%100!=0)||y%400==0)
{
if(m==3) n=(d+31+29)%7;
if(m==4) n=(d+31+29+31)%7;
if(m==5) n=(d+31+29+31+30)%7;
if(m==6) n=(d+31+29+31+30+31)%7;
if(m==7) n=(d+31+29+31+30+31+30)%7;
if(m==8) n=(d+31+29+31+30+31+30+31)%7;
if(m==9) n=(d+31+29+31+30+31+30+31+31)%7;
if(m==10) n=(d+31+29+31+30+31+30+31+31+30)%7;
if(m==11) n=(d+31+29+31+30+31+30+31+31+30+31)%7;
if(m==12) n=(d+31+29+31+30+31+30+31+31+30+31+30)%7;
}
else
{
if(m==3) n=(d+31+28)%7;
if(m==4) n=(d+31+28+31)%7;
if(m==5) n=(d+31+28+31+30)%7;
if(m==6) n=(d+31+28+31+30+31)%7;
if(m==7) n=(d+31+28+31+30+31+30)%7;
if(m==8) n=(d+31+28+31+30+31+30+31)%7;
if(m==9) n=(d+31+28+31+30+31+30+31+31)%7;
if(m==10) n=(d+31+28+31+30+31+30+31+31+30)%7;
if(m==11) n=(d+31+28+31+30+31+30+31+31+30+31)%7;
if(m==12) n=(d+31+28+31+30+31+30+31+31+30+31+30)%7;
}
}
W=W+n;
if(W>7) W=W%7;
else if(W==0) cout << "Sun\n";
else if(W==1) cout << "Mom\n";
else if(W==2) cout << "Tue\n";
else if(W==3) cout << "Wed\n";
else if(W==4) cout << "Thu\n";
else if(W==5) cout << "Fri\n";
else if(W==6) cout << "Sat\n";
}
return 0;
}