o
osc_z1hvg4cu

## D - The Lucky Week

Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date.

There was one day Edward suddenly found that if Monday was the 1st, 11th or 21st day of that month, he could remember the date clearly in that week. Therefore, he called such week "The Lucky Week".

But now Edward only remembers the date of his first Lucky Week because of the age-related memory loss, and he wants to know the date of the N-th Lucky Week. Can you help him?

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

The only line contains four integers Y, M, D and N (1 ≤ N ≤ 109) indicating the date (Y: year, M: month, D: day) of the Monday of the first Lucky Week and the Edward's query N.

The Monday of the first Lucky Week is between 1st Jan, 1753 and 31st Dec, 9999 (inclusive).

<h4< dd="">Output

For each case, print the date of the Monday of the N-th Lucky Week.

<h4< dd="">Sample Input

``````2
2016 4 11 2
2016 1 11 10``````

<h4< dd="">Sample Output

``````2016 7 11
2017 9 11``````

``````#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
struct node
{
int y, m, d;
};
vector<node>v;
int xq(int x)
{
x = x % 7;
if (x == 0) return 7;
else return x;
}
int f(int yy)
{
if (yy % 400 == 0 || (yy % 100 != 0 && yy % 4 == 0))
{
return 1;
}
else return 0;
}
int main()
{
int y = 1753;
int m = 1, d = 1;
int x = 1;
int k = 1;
node a;
a.y = 1753;
a.m = 1;
a.d = 1;
v.push_back(a);
for (int i = 1; i <= 6060; i++)//打表
{
while (1)
{
if (d == 21)
{
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
x = xq(x + 11);
}
else if (m != 2)
{
x = xq(x + 10);
}
else
{
if (f(y)) x = xq(x + 9);
else x = xq(x + 8);
}
if (m == 12)
{
m = 1;
d = 1;
y++;
}
else
{
m++;
d = 1;
}
if (x == 1)
{
node a;
a.y = y;
a.m = m;
a.d = d;
v.push_back(a);
break;
}
continue;
}
if (d == 1 || d == 11)
{
d = d + 10;
x = xq(x + 10);
if (x == 1)
{
node a;
a.y = y;
a.m = m;
a.d = d;
v.push_back(a);
break;
}
continue;
}
}
}
/*for (int i = 0; i < v.size(); i++)
{
cout << i + 1 << " " << v[i].y << " " << v[i].m << " " << v[i].d << endl;
}*/
int t;
scanf("%d", &t);
while (t--)
{
int y, m, d, n;
scanf("%d %d %d %d",&y,&m,&d,&n);
int x;
n--;
x = n / 2058;
n= n % 2058;

int yy = y;
while (y >= 2153)
{
y = y - 400;
}
for (int i = 0; i < v.size(); i++)
{
if (v[i].y == y&&v[i].m==m&&v[i].d==d)
{
printf("%d %d %d\n", v[i+n].y+yy-y+x*400, v[i + n].m, v[i + n].d);
break;
}
}

}
return 0;
}``````

o

### osc_z1hvg4cu #### 暂无文章

osc_2ak6wwpl
7分钟前
0
0

8分钟前
0
0
Spark SQL 中 Broadcast Join 一定比 Shuffle Join 快？那你就错了。

osc_k8v7r34l
9分钟前
7
0

osc_nfjwhlc1
10分钟前
15
0

osc_zsaazovz
11分钟前
17
0 