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