39.第几天——C语言初学者百题大战之十八

#include<stdio.h>
int main()
{
int i,j,year,month,day,MONTH[12]={31,28,31,30,31,30,31,31,30,31,30,31},D;
while(scanf("%d-%d-%d",&year,&month,&day)!=EOF)
{
if((year%4==0&&year%100!=0)||year%400==0)
{
MONTH[1]=29;
}
D=0;
for(i=0;i<month-1;i++)
{
D+=MONTH[i];
}
if(day<=MONTH[i])
{
D=D+day;
printf("%d\n",D);
}
else
printf("No\n");
}
} 
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d-%d-%d",&a,&b,&c);
    if((a%4==0&&a%100!=0)||(a%400==0))
{
    if(b==1){
    x=c;
    printf("%d\n",x);
    }
    if(b==2){
    x=c+31;
    printf("%d\n",x);
    }
     if(b==3){
    x=c+31+29;
    printf("%d\n",x);
    }
     if(b==4){
    x=c+31+29+31;
    printf("%d\n",x);
    }
     if(b==5){
    x=c+31+29+31+30;
    printf("%d\n",x);
    }
     if(b==6){
    x=c+31+29+31+30+31;
    printf("%d\n",x);
    }
     if(b==7){
    x=c+31+29+31+30+31+30;
    printf("%d\n",x);
    }
     if(b==8){
    x=c+31+29+31+30+31+30+31;
    printf("%d\n",x);
    }
     if(b==9){
    x=c+31+29+31+30+31+30+31+31;
    printf("%d\n",x);
    }
     if(b==10){
    x=c+31+29+31+30+31+30+31+31+30;
    printf("%d\n",x);
    }
     if(b==11){
    x=c+31+29+31+30+31+30+31+31+30+31;
    printf("%d\n",x);
    }
     if(b==12){
    x=c+31+29+31+30+31+30+31+31+30+31+30;
    printf("%d\n",x);
    }
}
else
{
    if(b==1){
    x=c;
    printf("%d\n",x);
    }
    if(b==2){
    x=c+31;
    printf("%d\n",x);
    }
     if(b==3){
    x=c+31+28;
    printf("%d\n",x);
    }
     if(b==4){
    x=c+31+28+31;
    printf("%d\n",x);
    }
     if(b==5){
    x=c+31+28+31+30;
    printf("%d\n",x);
    }
     if(b==6){
    x=c+31+28+31+30+31;
    printf("%d\n",x);
    }
     if(b==7){
    x=c+31+28+31+30+31+30;
    printf("%d\n",x);
    }
     if(b==8){
    x=c+31+28+31+30+31+30+31;
    printf("%d\n",x);
    }
     if(b==9){
    x=c+31+28+31+30+31+30+31+31;
    printf("%d\n",x);
    }
     if(b==10){
    x=c+31+28+31+30+31+30+31+31+30;
    printf("%d\n",x);
    }
     if(b==11){
    x=c+31+28+31+30+31+30+31+31+30+31;
    printf("%d\n",x);
    }
     if(b==12){
    x=c+31+28+31+30+31+30+31+31+30+31+30;
    printf("%d\n",x);
}
    return 0;
}
}

猜你喜欢

转载自www.cnblogs.com/Estwind/p/9784751.html
今日推荐