今夕何夕
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 568 Accepted Submission(s): 168
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 568 Accepted Submission(s): 168
Problem Description
今天是2017年8月6日,农历闰六月十五。
小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。
为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星期数一样?比如今天是8月6日,星期日。下一个也是星期日的8月6日发生在2023年。
小贴士:在公历中,能被4整除但不能被100整除,或能被400整除的年份即为闰年。
Input
第一行为T,表示输入数据组数。
第一行为T,表示输入数据组数。
每组数据包含一个日期,格式为YYYY-MM-DD。
1 ≤ T ≤ 10000
YYYY ≥ 2017
日期一定是个合法的日期
Output
对每组数据输出答案年份,题目保证答案不会超过四位数。
对每组数据输出答案年份,题目保证答案不会超过四位数。
Sample Input
3
2017-08-06
2017-08-07
2018-01-01
3
2017-08-06
2017-08-07
2018-01-01
Sample Output
2023
2023
2024
2023
2023
2024
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#include <stack>
#include <climits>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int T[10003][13][35];
int yue[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int num = 1;
int year = 1,m = 1,n = 1;
memset(T,-1,sizeof(T));
while(!(year == 10000 && m == 1 && n == 1))
{
if(year%4==0 && year %100!=0 || year %400 == 0)
yue[2] = 29;
else
yue[2] = 28;
T[year][m][n] = num++;
int j = n / yue[m];
n++;
if(j)
{
n = 1;
j = (m) / 12;
m++;
if(j) m = 1;
year += j;
}
}
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d-%d-%d",&year,&m,&n);
int be = T[year][m][n];
for(int i = year+1;i < 10000; i++)
{
if(T[i][m][n] != -1 && (T[i][m][n]-be) % 7 == 0)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}