没有用到类
而且不能计算到公元前
#include <stdio.h> #include <stdlib.h> int Year(int year) { if(year%4==0&&year%100!=0||year%400==0)return 1; else return 0; } void daytoyear(int v[]) { int day=0; int i=0,j=0,k=0; int count=0; int star[13]={0,1,32,60,91,121,152,182,213,244,274,304,334};//0-6 int chazhi=0; for(i=1;i<v[0];i++) { if(Year(i)) count+=366;else count+=365;} if(Year(v[0])){for(j=3;j<12;j++)star[j]++; } count=count+star[v[1]]+v[2]-1; if(Year(v[0])){for(j=3;j<12;j++)star[j]--; } printf(" %d年 %d月%d 日 %d 天后的时间如下\n",v[0],v[1],v[2],v[3]); for(i=1;day<(count+v[3]);i++) { if(Year(i))day+=366;else day+=365; } if(Year(i)){ day-=366; for(j=3;j<12;j++)star[j]++;} else day-=365; chazhi=count+v[3]-day; for(j=1;j<13;j++){if(star[j]<chazhi)k++;} printf(" %d年 %d月%d 日 \n",i-1,k,chazhi-star[k]); } void daytoyear1(int v[]) { int day=0; int i=0,j=0,k=0; int count=0; int star[13]={0,1,32,60,91,121,152,182,213,244,274,304,334};//0-6 int chazhi=0; for(i=1;i<v[0];i++) { if(Year(i)) count+=366;else count+=365;} if(Year(v[0])){for(j=3;j<12;j++)star[j]++; } count=count+star[v[1]]+v[2]-1; if(Year(v[0])){for(j=3;j<12;j++)star[j]--; } printf(" %d年 %d月%d 日 %d 天前的时间如下\n",v[0],v[1],v[2], v[3]); for(i=1;day<(count-v[3]+1);i++) { if(Year(i))day+=366;else day+=365; } if(Year(i)){ day-=366; for(j=3;j<12;j++)star[j]++;} else day-=365; chazhi=count-v[3]-day; for(j=1;j<13;j++){if(star[j]<chazhi)k++;} printf(" %d年 %d月%d 日 \n",i-1,k+1,chazhi-star[k]+1); } void main() { int x[4]={1,1,1,400};//2-2-4 int y[4]={2,2,4,399}; daytoyear(x); daytoyear1(y); }
存在1天的偏差 然后这里不同的人有不同的理解1号和3号间的天数有2天或3天,看自己怎样理解
时间: 2024-10-21 07:36:00