题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdbool.h> #include <stdio.h> int isLeap(int year) { if(year%4==0&&year%100!=0||year%400==0) return 1; else return 0;; } int main() { int year,month; int day[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; while(scanf("%d %d\n",&year,&month)!=EOF) { if(isLeap(year)&&month==2) printf("29\n"); else printf("%d\n",day[month-1]); } }
1.对闰年下的2月做特殊处理,其他情况直接存储对应天数