该程序过了CCF100000随机大数据(即题目中的julian3.in)
但是洛谷评分60pts,有错误
具体而言,我有几处怀疑的地方
1.分割线(分割儒略历和格里高利的时间点)
2.公元-1变到+1的代码错误
3.cy函数编写错误
4.未知糖式原因
#include <bits/stdc++.h>
using namespace std;
#define int long long
int m[13], y[400];
int Q, n, A;
int cycle = 365 + 365 + 365 + 366;
int start_year = -4713;
bool leap(int k) {
if ((k % 4 != 0) || ((k % 100 == 0) && (k % 400 != 0)))
return 0;
else
return 1;
}
void month() {
m[1] = 31; m[2] = 28; m[3] = 31; m[4] = 30; m[5] = 31; m[6] = 30;
m[7] = 31; m[8] = 31; m[9] = 30; m[10] = 31; m[11] = 30; m[12] = 31;
}
void print(int y, int d, int man) {
m[2] = 28 + man;
for (int i = 1; i <= 12; i++) {
if (d < m[i] && y > 0) {
cout << d + 1 << " " << i << " " << y << endl;
break;
}
if (d < m[i] && y < 0) {
cout << d + 1 << " " << i << " " << -y << " BC" << endl;
break;
}
d = d - m[i];
}
m[2] = 28;
}
void cy(int s) { //calculate year
int sy = 1583;
int cnt = 1583;
cnt = cnt + (s / A) * 400;
s = s % A;
while (s >= y[(cnt ) % 400]) {
s = s - y[cnt % 400];
cnt++;
}
print(cnt + 1, s, leap(cnt + 1));
}
signed main() {
month();
A = 0;
for (int i = 1; i <= 400; i++) {
if (!leap(i))
y[i - 1] = 365;
else
y[i - 1] = 366;
A = A + y[i - 1];
}
cin >> Q;
while (Q--) {
cin >> n;
if (n < 2299526) { //Seprating LINE
int p = n / cycle;
int q = n % cycle;
int u = start_year + p * 4;
//cout << "u=" << u << endl;
if (u >= 0)
u++;
if (q >= 0 && q <= 365) {
print(u, q, 1);
} else {
u = u + ceil((q - 365) / 365.0);
q = (q - 366) % 365;
print(u, q, 0);
}
} else {
n = n - 2299526;
if (n >= 0 && n <= 17 + 30 + 31) { //special for year of 1582
if (n >= 0 && n <= 17) {
cout << 14 + n << " 10 1582" << endl;
} else if (n >= 18 && n <= 37) {
cout << n - 17 << " 11 1582" << endl;
} else {
cout << n - 37 << " 12 1582" << endl;
}
} else {
n = n - 17 - 30 - 31;
cy(n);
}
}
}
return 0;
}