题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdio.h> int main() { int a, b; int i; int arr1[] = {1, 3, 5, 7, 8, 10, 12}; int arr2[] = {4, 6, 9, 11}; while (scanf("%d%d", &a, &b) != EOF) { for (i = 0; i <= 6; i++) { if (b == arr1[i]) { printf("31\n"); } else if (b == arr2[i]) { printf("30\n"); } } if (b == 2) { //闰年和平年只有2月有区别 if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0)) { printf("29\n"); } else { printf("28\n"); } } } return 0; }