题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
将闰年和平年的月份用数组表示出来,唯一不同点就是二月份
#include <stdio.h> int main() { int y=0; int m=0; int i=0; int arr1[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int arr2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; while(scanf("%d%d",&y,&m)!=EOF) { if(y%4==0&&y%100!=0||y%400==0) { printf("%d\n",arr1[m]); } else { printf("%d\n",arr2[m]); } } return 0; }