#include<bits/stdc++.h>
using namespace std;
int q,r,year__,k,yearans,monthans,dayans;
int month1[]={0,31,28,31,30,31,30,31,31,30,31,30,31},month2[]={0,31,29,31,30,31,30,31,31,30,31,30,31},month1582[]={0,0,0,0,0,0,0,0,0,0,17,30,31};
bool rn(int x){
return x%4==0&&x%100!=0||x%400==0;
}
void rll(){//儒略历
int k=r/1461;
r-=k*1461;
yearans+=4*k;
if(r==0){
if(yearans<0)
cout<<"31 12 "<<(-yearans+1)<<" BC\n";
else
cout<<"31 12 "<<yearans-1<<endl;
return ;
}
if(r<=366){
for(monthans=1;monthans<=12;monthans++){
if(r>month2[monthans]){
r-=month2[monthans];
}
else{
dayans=r;
break;
}
// cout<<r<<endl;
}
}
else{
yearans++;
r-=366;
for(int i=1;i<=3;i++)
if(r>365){
yearans++;
r-=365;
}
for(monthans=1;monthans<=12;monthans++){
if(r>month1[monthans]){
r-=month1[monthans];
}else{
dayans=r;
break;
}
}
}
// cout<<r<<endl;
if(yearans<0)
cout<<dayans<<' '<<monthans<<' '<<-yearans<<" BC\n";
else{
cout<<dayans<<' '<<monthans<<' '<<yearans+1<<"\n";
}
}
void glgll(){//格里高利历
r-=2299161;
// cout<<r;
if(r<=78){
yearans=1582;
for(monthans=10;monthans<=12;monthans++){
if(r>month1582[monthans]){
r-=month1582[monthans];
}
else{
dayans=r;
break;
}
}
if(monthans==10)
dayans+=14;
printf("%d %d %d\n",dayans,monthans,yearans);
}else if(r<=78+365){
yearans=1583;
r-=78;
for(monthans=1;monthans<=12;monthans++){
if(r>month1[monthans]){
r-=month1[monthans];
}else{
dayans=r;
break;
}
}
printf("%d %d %d\n",dayans,monthans,yearans);
}else{
r-=(365+78);
yearans=1583;
int k=r/146097;
r-=k*146097;
yearans+=k*400;
if(r==0){
cout<<"31 12 "<<yearans-1<<endl;
return ;
}
dayans=-1;
while(dayans==-1){
yearans++;
if(rn(yearans))
for(monthans=1;monthans<=12;monthans++){
if(r>month2[monthans]){
r-=month2[monthans];
}
else{
dayans=r;
break;
}
}
else{
for(monthans=1;monthans<=12;monthans++){
if(r>month1[monthans]){
r-=month1[monthans];
}
else{
dayans=r;
break;
}
}
}
}
printf("%d %d %d\n",dayans,monthans,yearans);
}
}
int main(){
// freopen("7075.in","r",stdin);
// freopen("7075.out","w",stdout);
cin>>q;
while(q--){
cin>>r;
r++;
yearans=-4713;
if(r<=2299161){//¹«ÔªÇ°
rll();
}
else{
glgll();
}
}
return 0;
}
附错误数据:
in: 1
2194421
正确输出:31 12 1295
我的输出:31 12 1294