题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
//一种思路解题 #include<stdio.h> int main() { int year, mon; while (scanf("%d%d", &year, &mon) != EOF) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {//判断是否闰年 if (mon == 2) { printf("29\n"); } else if (mon < 8) { if (mon % 2 == 0) {//八月是转折点:八月前偶数月份是小月,八月后偶数月份为大月 printf("30\n"); } else { printf("31\n"); } } else { if (mon % 2 == 0) { printf("31\n"); } else { printf("30\n"); } } } else { if (mon == 2) { printf("28\n"); } else if (mon < 8) { if (mon % 2 == 0) { printf("30\n"); } else { printf("31\n"); } } else { if (mon % 2 == 0) { printf("31\n"); } else { printf("30\n"); } } } } return 0; }