今夕何夕
Accepts: 1345
Submissions: 5533
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
将所有年月日打表即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1e9 + 2;
const double pi = acos(-1.0);
bool isrun(int year)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
return 0;
}
int a[10000][13][32] = { 0 };
int month[] = { 29,31,28,31,30,31,30,31,31,30,31,30,31 };
int main()
{
memset(a, -1, sizeof(a));
int p = 0;
for (int year = 2017; year <= 9999; year++)
{
bool run = isrun(year);
for (int m = 1; m <= 12; m++)
{
if (run&&m == 2)
{
for (int d = 1; d <= month[0]; d++)
{
a[year][m][d] = p;
p++;
p %= 7;
}
continue;
}
for (int d = 1; d <= month[m]; d++)
{
a[year][m][d] = p;
p++;
p %= 7;
}
}
}
int t;
scanf("%d", &t);
while (t--)
{
int y, m, d;
scanf("%d-%d-%d", &y, &m, &d);
for (int i = y + 1; i <= 9999; i++)
{
if (a[i][m][d] == a[y][m][d])
{
printf("%d
", i);
break;
}
}
}
}