[挑战记录]儒略历

两年前就差点切掉,现在终于切了
没什么好说的,就是用计算器进行手算年份

#include<cstdio>
#include<cstring>
#include<string>
#define WR WinterRain
#define int long long
using namespace std;
const int WR=1001000;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int q,n;
int lunar_sum;
int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch>'9'||ch<'0'){
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=(s<<3)+(s<<1)+ch-'0';
        ch=getchar();
    }
    return s*w;
}
void count_julian(int year,int k,bool lunar){
    if(lunar) month[2]++;
    int tot=0,mth;
    for(int i=1;i<=12;i++){
        tot+=month[i];
        if(tot>=k){
            mth=i;
            k-=(tot-month[i]);
            if(year-4713<0) printf("%lld %lld %lld BC\n",k,mth,4713-year);
            else printf("%lld %lld %lld\n",k,mth,year-4712);
            break;
        }
    }
    if(lunar) month[2]--;
}
void count_gregory(int year,int k,bool lunar){
    if(lunar) month[2]++;
    int tot=0,mth;
    bool flag=false;
    for(int i=1;i<=12;i++){
        tot+=month[i];
        if(tot>=k){
            mth=i;
            k-=(tot-month[i]);
            printf("%lld %lld %lld\n",k,mth,year+1600);
            flag=true;
            break;
        }
    }
    if(!flag) printf("1 1 %lld\n",year+1601);
    if(lunar) month[2]--;
}
signed main(){
    freopen("julian.in","r",stdin);
    freopen("julian.out","w",stdout);
    for(int i=1;i<=400;i++){
        if((i%4==0&&i%100!=0)||i%400==0) lunar_sum++;
    }
    q=read();
    while(q--){
        n=read();
        if(n<=2299160){
            int k=n%(365*4+1),year=n/(365*4+1)*4;
            bool lunar=true;
            if(k>=366) k-=365,year++,lunar=false;
            if(k>=366) k-=365,year++;
            if(k>=366) k-=365,year++;
            if(lunar==1) k++;
            count_julian(year,k,lunar);
        }else{
            n+=10;
            if(n<=2305457){
                int k=n%(365*4+1),year=n/(365*4+1)*4;
                bool lunar=true;
                if(k>=366) k-=365,year++,lunar=false;
                if(k>=366) k-=365,year++;
                if(k>=366) k-=365,year++;
                if(lunar==1) k++;
                count_julian(year,k,lunar);
            }else{
                n-=2305458;
                int k=n%(365*400+lunar_sum),year=n/(365*400+lunar_sum)*400;
                bool lunar=true;
                if(k>=366) k-=365,year++,lunar=false;
                for(int i=2;i<=399;i++){
                    if(i%4==0&&i%100!=0){
                        if(k>=367) k-=366,year++,lunar=true;
                        else break;
                    }
                    else{
                        if(k>=366) k-=365,year++,lunar=false;
                        else break;
                    }
                }
                if(lunar) k++;
                count_gregory(year,k,lunar);
            }
        }
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

posted @ 2022-10-02 18:12  冬天丶的雨  阅读(40)  评论(0编辑  收藏  举报
Live2D