Home > Back-end >  C of the new turn, my code may be a little long, thank you for your patience finish see ~
C of the new turn, my code may be a little long, thank you for your patience finish see ~

Time:03-13

[problem description]
Known on Tuesday is January 1, 1980,
Arbitrary input a date, this is the day of the week,
[form] input
From the keyboard input line of string & amp; ldquo; Y -m - D& rdquo; , it is a valid calendar date, including Y for years (1980 & amp; Le; Y& Le; ), 3000 M for the month, D for the day, all not prefixed 0,
[] output form
In the screen output,
Output is only a line, on behalf of the string that week, on Monday to Sunday, respectively output Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, to output a carriage return at the end of the line, judging algorithm is a leap year:

Can be divided exactly by 4 years and can't be divided exactly by 100, or divisible by four hundred,
[input sample]
The 2004-1-6
[output sample]
Tuesday
My code:
# include
# include
using namespace std;
Int main () {
Int y, m, d, I=0;
Long long e, f, g, h;
char a;
Cin> Y> A> M> A> d;
E=abs (y - 1980);
If (y % 4==0 & amp; & Y % 100 | | y %==0 400)
{f=e/4;
If (m==2) g=f * (365 + 365 + 365 + 366) + 31 + d;
Else if (m==1) g=f * (365 + 365 + 365 + 366) + d.
Else if (m % 2 & amp; & m<8) g=f * (365 + 365 + 365 + 366) + d + 31 + m/m/2 * 2 * 30 to 1;
Else if (m % 2==0 & amp; & mElse if (m % 2 & amp; & M> 8) g=f * (365 + 365 + 365 + 366) + d + 5 + 3 * 30 * 31-1 + (m - 8)/2 * 61;
Else if (m % 2==0 & amp; & M> 8) g=f * (365 + 365 + 365 + 366) 31 + + d + 5 * 3 * 30-1 + (m - 1)/2 * 31 + (m - 8)/2 * 30; }
The else
{f=e/4; H=e % 4;
If (y==2200) I=1;
If (y==2300), I=2;
If (y==2500) I=3;
If (m==1) g=f * (365 + 365 + 365 + 366) - 365 + 1 + I + h * d;
Else if (m==2) g=f * (365 + 365 + 365 + 366) - 365 + 1 + 31 + I + h * d;
Else if (m % 2 & amp; & m<8) g=f * (365 + 365 + 365 + 366) 365 + I + h * 1 + 31 + m/m/2 * 2 * 2 + 30 - d;
Else if (m % 2==0 & amp; & m<=8) g=f * (365 + 365 + 365 + 366) 365 + I + h * * 31 + 1 + m/2 (m - 2)/2 * 2 + 30 - d;
Else if (m % 2 & amp; & M> 8) g=f * (365 + 365 + 365 + 366) 365 + I + h * 1 + 5 * 31 + 2 + 3 * 30 - (m - 8)/2 * 61 + d;
Else if (m % 2==0 & amp; & M> 8) g=f * (365 + 365 + 365 + 366) 365 + I + h * 1 + 5 * 31 + 2 + 3 * 30 - (m - 1)/2 * 31 + (m - 8)/2 * 30 + d; }
The switch (g % 7)
{case 1: cout<& lt;" Tuesday." break;
Case 2: cout<& lt;" Wednesday." break;
Case 3: cout<& lt;" Thursday "; break;
Case 4: cout<& lt;" Friday "; break;
Case 5: cout<& lt;" Saturday "; break;
Case 6: cout<& lt;" Sunday "; break;
Case 0: cout<& lt;" Monday "; break;
}
return 0;
}
But the test sample should be Thursday, the 2500-4-29 results and output is Friday, I ask bosses error correction ~
  • Related