义一个结构体变量(包括年、月、日),编程序,要求输入年月日,计算并输出该日 在本年中第几天。
注意本题一定要定义结构体变量这是我写的:#include<stdio.h>structDATE{intyear;intmounth;intday;};intmain(){...
注意本题一定要定义结构体变量
这是我写的:
#include<stdio.h>
struct DATE
{
int year;
int mounth;
int day;
};
int main()
{
struct DATE date;
int leap_1,leap_2;
int sum;
while(scanf("%d%d%d",&date.year,&date.mounth,&date.day)!=EOF)
{
leap_1=0,leap_2=0;
if(date.year%100!=0&&date.year%4==0 || date.year%400==0)
{
leap_1=1;
}
switch(date.mounth)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default :printf("Input error!\n");leap_2=1;break;
}
sum=sum+date.day;
if(leap_1==1)
{
sum=sum+1;
}
if(leap_2==0)
{
printf("%d\n",sum);
}
}
return 0;
}
为什么在OJ平台上通不过? 展开
这是我写的:
#include<stdio.h>
struct DATE
{
int year;
int mounth;
int day;
};
int main()
{
struct DATE date;
int leap_1,leap_2;
int sum;
while(scanf("%d%d%d",&date.year,&date.mounth,&date.day)!=EOF)
{
leap_1=0,leap_2=0;
if(date.year%100!=0&&date.year%4==0 || date.year%400==0)
{
leap_1=1;
}
switch(date.mounth)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default :printf("Input error!\n");leap_2=1;break;
}
sum=sum+date.day;
if(leap_1==1)
{
sum=sum+1;
}
if(leap_2==0)
{
printf("%d\n",sum);
}
}
return 0;
}
为什么在OJ平台上通不过? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询