pta上一道题有一个测试点不过,不是格式问题,求大佬解答。
问题描述:
#include<stdio.h>
#include<stdlib.h>
int leapyear (int year);
int main(){
char s[11];
char s2[5];
char s3[5];char s4[5];
scanf("%s",s);
int i;
for(i=0;i<4;i++ ){
s2[i]=s[i];
};
for(i=5;i<7;i++ ){
s3[i-5]=s[i];
};
for(i=8;i<10;i++ ){
s4[i-8]=s[i];
};
int num1,num2,num3;
num1=atoi(s2); num2=atoi(s3); num3=atoi(s4);
//printf("%d",num1);
int mou;
if(leapyear(num1)){
switch(num2){
case 1:mou=0;break;
case 2:mou=31;break;
case 3:mou=31+29;break;
case 4:mou=31+29+31;break;
case 5:mou=31+29+31+30;break;
case 6:mou=151;break;
case 7:mou=181;break;
case 8:mou=212;break;
case 9:mou=243;break;
case 10:mou=273;break;
case 11:mou=304;break;
case 12:mou=334;break;
}
}else switch(num2){
case 1:mou=0;break;
case 2:mou=31;break;
case 3:mou=31+28;break;
case 4:mou=31+28+31;break;
case 5:mou=31+28+31+30;break;
case 6:mou=150;break;
case 7:mou=180;break;
case 8:mou=211;break;
case 9:mou=242;break;
case 10:mou=272;break;
case 11:mou=303;break;
case 12:mou=333;break;
}
int sum=0;
sum=mou+num3;
printf("%d\n",sum);
// printf("%d\n",mou);printf("%d\n",num3);
return 0;
}
int leapyear(int year){
if(year%4==0){
if(year%100==0&&year%400!=0){
return 0;
}else return 1;
}else return 0;
}