题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdio.h> int main() { //多组输入,一行有两个整数,分别表示年份和月份,用空格分隔。 //针对每组输入,输出为一行,一个整数,表示这一年这个月有多少天。 int year = 0; int month = 0; int i = 0; int arr[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; while (scanf("%d %d",&year,&month) != EOF) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { printf("%d\n", arr[month-1]); } else { if (month == 2) { printf("%d\n",arr[month-1]-1); } else { printf("%d\n", arr[month-1]); } } } return 0; }