20pts求助,调不出来力
查看原帖
20pts求助,调不出来力
231800
Veranda楼主2022/10/18 00:17
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int Q;
    cin >> Q;
    while(Q --){
        long long n;
        cin >> n;
        long long y = -4713,m = 1,d;
        n ++;
        for(int i = 1;;i ++){
            if(i == 13) i = 1,y ++;
            if(y == 0) y ++;
            if(n <= month[i]){
                d = n;
                m = i;
                break;
            }
            if(i == 2){
                if(y < 0 && (y + 1) % 4 == 0) n -= 29;
                else if(y > 0 && y < 1582 && y % 4 == 0) n -= 29;
                else if(y > 1582 && (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))){
                    n -= 29;
                }
                else n -= 28;
            }
            else if(y == 1582 && i == 10) n -= 21;
            else {
                //cout << y << " " << i << endl;
                n -= month[i];
            }
            
            
        }
        if(y < 0){
            cout << d << " " << m << " " << abs(y) << " BC" << endl;
        }
        else{
            cout << d << " " << m << " " << y << endl;
        }
    }
}

且先不论时间复杂度

很直白的模拟,很奇怪的错误->20pts

2022/10/18 00:17
加载中...