qq_30502811 于 2016.03.27 19:30 提问

int main(){
int num,i=0,a=0,b=0,c=0;
int year=0,month=0,day=0;
scanf("%d",&num);
a=(num/365)+1777;
while(a>1){
if((a%4)==0||((a%100)==0&&(a%400)==0)){
i++;
}
a--;
}
b=num-(i*366+((num/365)-i)*365);
if(b<=245){
if(b<=31) month=5;
if(b>31&&b<=61) month=6;
if(b>61&&b<=92) month=7;
if(b>92&&b<=123) month=8;
if(b>123&&b<=153) month=9;
if(b>153&&b<=184) month=10;
if(b>184&&b<=214) month=11;
if(b>214&&b<=245) month=12;
switch(month)
{
case 5: day=b;
break;
case 6: day=b-31;
break;
case 7: day=b-61;
break;
case 8: day=b-92;
break;
case 9: day=b-123;
break;
case 10: day=b-153;
break;
case 11: day=b-184;
break;
case 12: day=b-214;
break;
default: break;

}

}
if(b>245){
c=b-245;
if(num%4==0||((num%100)==0&&(num%400)==0)){
if(c<=30)month=1;
if(30<c&&c<=60)month=2;
if(60<c&&c<=91)month=3;
if(c>91)month=4;
switch(month)
{
case 1: day=c;
break;
case 2: day=c-30;
break;
case 3: day=c-60;
break;
case 4: day=c-91;
break;
default: break;
}
}
else if((num%4)!=0&&((num%100)!=0&&(num%400)!=0)){
if(c<=30)month=1;
if(30<c&&c<=59)month=2;
if(60<c&&c<=90)month=3;
if(c>90)month=4;
switch(b)
{
case 1: day=c;
break;
case 2: day=c-30;
break;
case 3: day=c-59;
break;
case 4: day=c-90;
break;
default: break;
}
}

}
year=(num/365)+1777;
printf("\nThe year you want to know is %d-%d-%d\n",year,month,day);
return 0;

}

4个回答

caozhy      2016.03.27 19:47

caozhy      2016.03.27 19:48
huixion   2016.03.27 20:06

bealing   2016.03.27 20:47

qq_30502811 太大意了，果然只是因为这个小bug，谢谢谢谢