Result: Accepted
Time: 29ms
Memory: 1716kB
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int dp(int x)
{
if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0)
{
return 1;
}
return 0;
}
int main()
{
int aa, bb, cc;
while (cin >> aa >> bb >> cc)
{
ll ans = 0;
if (aa >= 2016)
{
for (int i = 2016; i < aa; i++)
{
if (dp(i))
{
ans += 366;
}
else
{
ans += 365;
}
}
if (dp(aa))
{
int yue[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
for (int j = 1; j < bb; j++)
{
ans += yue[j - 1];
}
}
else
{
int yue[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
for (int j = 1; j < bb; j++)
{
ans += yue[j - 1];
}
}
ans = ans + (cc - 1);
ans = ans % 7;
if (ans == 0) printf("Friday\n");
if (ans == 1) printf("Saturday\n");
if (ans == 2) printf("Sunday\n");
if (ans == 3) printf("Monday\n");
if (ans == 4) printf("Tuesday\n");
if (ans == 5) printf("Wednesday\n");
if (ans == 6) printf("Thursday\n");
}
if (aa < 2016)
{
int count = 0;
for (int i = aa+1; i <= 2016; i++)
{
if (dp(i))
{
ans += 366;
}
else
{
ans += 365;
}
}
if (dp(aa))
{
int yue[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
for (int j = 1; j < bb; j++)
{
count += yue[j - 1];
}
count += cc;
ans = ans + (366 - count);
}
else
{
int yue[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
for (int j = 1; j < bb; j++)
{
count += yue[j - 1];
}
count += cc;
ans = ans + (365 - count);
}
ans = ans % 7;
if (ans == 1) printf("Friday\n");
if (ans == 0) printf("Saturday\n");
if (ans == 6) printf("Sunday\n");
if (ans == 5) printf("Monday\n");
if (ans == 4) printf("Tuesday\n");
if (ans == 3) printf("Wednesday\n");
if (ans == 2) printf("Thursday\n");
}
}
return 0;
}