文章
4
粉丝
64
获赞
1
访问
3.9k
#include<stdio.h>
struct node
{
int year,month,day,x;
}p;
int s[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
while (scanf("%d %d",&p.year,&p.x)!=EOF)
{
if(p.year%400==0||(p.year%4==0&&p.year%100!=0))
s[2]=29;
p.month=1;
while (p.x>s[p.month])
{
p.x=p.x-s[p.month];
p.month++;
}
printf("%4d-%02d-%02d\n",p.year,p.month,p.x);
}
return 0;
}
登录后发布评论
int s[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};把这行放while循环里面
int s[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};没有参与多组的迭代,一开始你的s[2]是28,一旦出现了个29,那么你的s[2]一直是29,要么把s[13]定义放下面;while (scanf("%d %d",&p.year,&p.x)!=EOF)
{int s[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};...;
要么就if( year%400==0 || year%4==0&&year%100!=0)
s[2]=29;
else s[2]=28;
少一种情况,不是闰年,但输入的day=366,变成下一年了
if(p.year%400==0||(p.year%4==0&&p.year%100!=0))
s[2]=29;
else s[2]=28;