题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
//个人感觉最简单的方法可以看一看
#include<stdio.h>
int fun(int y){
return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0);
}
int main()
{
int y = 0;
int m = 0;
int d = 0;
int days[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
while (scanf("%d%d", &y, &m) == 2)
{
int d = days[m];
if (fun(y) == 1 && m == 2)
{
d++;
}
printf("%d\n", d);
}
return 0;
}