题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdio.h> // 平年每年每月的天数 int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int getDays(int year, int month) { if (month != 2) return days[month]; else { int leap = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); return 28 + leap; } } int main() { int year, day; while (scanf("%d %d", &year, &day) != EOF) { int res = getDays(year, day); printf("%d\n", res); } return 0; }