题解 | #BC74 获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdio.h> #include <stdbool.h> #define LeapYear(y) (y%400 == 0) || ((y%4==0) && (y%100!=0)) int main() { int y, m, d; int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while(scanf("%d%d", &y, &m) != EOF) { d = days[m-1]; if ((LeapYear(y) == true) && (m == 2)) { d = 29; } printf("%d\n", d); } return 0; }