规律题。400年一个大闰年一循环。次数2058一循环。打表得出规律。直接模拟求出即可
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f3f3f3f3f
const int maxn=1e5+9;
#define mem(aa,bb) memset(aa,bb,sizeof(aa))
#define PI acos(-1.0)
int num[30]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int ans[10000];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int year,month,data,week=1,day,sum_day=1,sum=0,all=8000000,N;
scanf("%d%d%d%d",&year,&month,&data,&N);
N--;
if(N%2058==0)
{
year+=N/2058*400;
printf("%d %d %d\n",year,month,data);
}
else
{
year+=N/2058*400;
data++;week++;
N%=2058;
// printf("%d %d\n",year,N);
while(1)
{
if(week==1&&(data==1||data==11||data==21))
{
sum++;
if(sum==N)
{
printf("%d %d %d\n",year,month,data);
break;
}
}
if((year%4==0&&year%100!=0)||(year%400==0)) num[2]=29;
else num[2]=28;
if(data+1>num[month])
{
if(month+1>12)
{
month=1;
year++;
}
else month++;
data=1;
}
else
data++;
week++;
if(week>7) week=1;
}
}
}
return 0;
}