只过了样例一,代码如下:
#include<bits/stdc++.h>
using namespace std;
long long q,r[100000000];
long long i,day,month,year,y,m;
int a;
char B,C;
int main()
{
cin>>q;
for(i=1;i<=q;i++) cin>>r[i];
for(i=1;i<=q;i++)
{
day=0;
month=0;
year=0;
y=0;
m=0;
year=-4713;
while(r[i]>=365) //year-------------------------------------
{
for(a=-4713;;)
{
if(a<=1852)
{
if(a%4==0)
{
r[i]=r[i]-366;
year++;
a++;
if(r[i]<365) break;
}
else
{
r[i]=r[i]-365;
year++;
a++;
if(a%4==0)
{
if(r[i]<366) break;
}
else
{
if(r[i]<365) break;
}
}
}
else
{
if(a%4==0&&a%100!=0||a%400==0)
{
r[i]=r[i]-366;
year++;
a++;
if(r[i]<365) break;
}
else
{
r[i]=r[i]-365;
year++;
a++;
if(a%4==0&&a%100!=0||a%400==0)
{
if(r[i]<366) break;
}
else
{
if(r[i]<365) break;
}
}
}
}
}
while(r[i]>=28) //month----------------------------------
{
for(a=1;;)
{
int year1;
year1=year;
if(year<=-1) year1=-year;
else year1=year;
if(year<=1852)
{
if(a<=7)
{
if(a%2!=0)
{
r[i]=r[i]-31;
m++;
a++;
if(a==2)
{
if(year1%4==0)
{
if(r[i]<29) break;
}
else
{
if(r[i]<28) break;
}
}
else
{
if(r[i]<30) break;
}
}
else if(a%2==0&&a!=2)
{
r[i]=r[i]-30;
m++;
a++;
if(r[i]<31) break;
}
else if(a==2)
{
if(year1%4==0) r[i]=r[i]-29;
else r[i]=r[i]-28;
m++;
a++;
if(r[i]<31) break;
}
}
else
{
if(a%2!=0)
{
r[i]=r[i]-30;
m++;
a++;
if(r[i]<31) break;
}
else if(a%2==0)
{
r[i]=r[i]-31;
m++;
a++;
if(r[i]<30) break;
}
}
}
else
{
if(a<=7)
{
if(a%2!=0)
{
r[i]=r[i]-31;
m++;
a++;
if(a==2)
{
if(year1%4==0&&year1%100!=0||year1%400==0)
{
if(r[i]<29) break;
}
else
{
if(r[i]<28) break;
}
}
else
{
if(r[i]<30) break;
}
}
else if(a%2==0&&a!=2)
{
r[i]=r[i]-30;
m++;
a++;
if(r[i]<31) break;
}
else if(a==2)
{
if(year1%4==0&&year1%100!=0||year1%400==0) r[i]=r[i]-29;
else r[i]=r[i]-28;
m++;
a++;
if(r[i]<31) break;
}
}
else
{
if(a%2!=0)
{
r[i]=r[i]-30;
m++;
a++;
if(r[i]<31) break;
}
else if(a%2==0)
{
r[i]=r[i]-31;
m++;
a++;
if(r[i]<30) break;
}
}
}
}
}
month=1+m;
day=1+r[i]; //day
if(year<0) //判断公元
{
year=-year;
B='B';
C='C';
}
else
{
year=year+1;
C=' ';
B=' ';
if((year>1582)||(year==1582&&month>10)||(year==1582&&month==10&&day>=5))
{
day=day+10;
if(month%2==0)
{
if(day>31)
{
month=month+1;
day=day-31;
}
}
else
{
if(day>30)
{
month=month+1;
day=day-30;
}
}
}
}
cout<<day<<" "<<month<<" "<<year;
printf(" %c%c\n",B,C);
}
return 0;
}