这个代码只过了两个点,不能AC,这题非常恶心
#include<bits/stdc++.h>
using namespace std;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int is_leap(int year) {
if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) return 1;
else return 0;
}
bool is_leap_ru(int year, bool before) {
if(before && (year - 1) % 4 == 0) return 1;
else if((!before) && year % 4 == 0) return 1;
else return 0;
}
bool deal(int &year, int &m, int &d, bool spe_year) {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, num;
cin >> n;
while(n--) {
//现在是公元前
int year = 4713;
bool before = true;
cin >> num;
while(year > 0 && num >= is_leap_ru(year, before) + 365) {
year--;
num -= (is_leap_ru(year, before) + 365);
}
//到了公元年
if(year == 0) {
year = 1;
before = false;
while(year < 1582 && num >= is_leap_ru(year, before) + 365) {
year++;
num -= (is_leap_ru(year, before) + 365);
}
//到了格里高利历
if(year == 1582 && num >= 355) {
year++;
num -= 355;
}
while(year > 1582 && num >= (is_leap(year) + 365)) {
year++;
num -= (is_leap(year) + 365);
}
}
int m = 1, d = 1;
if(before) {
for(int i = 1; i <= 12; i++) {
if(i == 2 && num >= is_leap_ru(year, before) + month[i]) num -= (is_leap_ru(year, before) + month[i]);
else if(i != 2 && num >= month[i]) num -= month[i];
else {
m = i;
break;
}
}
d += num;
cout << d << " " << m << " " << year << " BC" << endl;
}else {
d = 0;
if(year < 1582) {
for(int i = 1; i <= 12; i++) {
if(i == 2 && num >= is_leap_ru(year, before) + month[i]) num -= (is_leap_ru(year, before) + month[i]);
else if(i != 2 && num >= month[i]) num -= month[i];
else {
m = i;
break;
}
}
d += num;
cout << d << " " << m << " " << year << endl;
}else if(year == 1582) {
for(int i = 1; i <= 12; i++) {
if(i == 2 && num >= is_leap(year) + month[i]) num -= (is_leap(year) + month[i]);
else if(i == 10 && num >= (month[i] - 10)) num -= (month[i] - 10);
else if(i != 2 && i != 10 && num >= month[i]) num -= month[i];
else {
m = i;
break;
}
}
d += num;
cout << d << " " << m << " " << year << endl;
}else if(year > 1582) {
for(int i = 1; i <= 12; i++) {
if(i == 2 && num >= is_leap(year) + month[i]) num -= (is_leap(year) + month[i]);
else if(i != 2 && num >= month[i]) num -= month[i];
else {
m = i;
break;
}
}
d += num;
cout << d << " " << m << " " << year << endl;
}
}
}
return 0;
}