题解 | #打印日期#

打印日期

http://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b

include<stdio.h>

include<stdbool.h>

int daytab[2][13] =
{
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};

bool isLeapYear(int year)
{
return (year%4 == 0&&year%100!=0)||(year%400 == 0);
}
int main()
{
int year,month,day;
int number;
while(scanf("%d%d",&year,&number)!=EOF)
{
month=0;
int row = isLeapYear(year);
while(number>daytab[row][month])
{
number-=daytab[row][month];
month++;
}
day=number;
printf("%4d-%02d-%02d",year,month,day);
}
return 0;
}

全部评论
大神,我写的又慢又麻烦怎么办
点赞 回复 分享
发布于 2021-05-08 10:31

相关推荐

过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务