题解 | #今年的第几天?#
今年的第几天?
https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d
#include <stdio.h> #define bool int #define TRUE 1 #define FALSE 0 //今天是今年的第几天 int mDays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int year, month, day; //年月日 while(scanf("%d %d %d", &year, &month, &day) != EOF){ bool isLeapYear = FALSE; //判断是不是闰年 if (year % 400 == 0 || year % 100 != 0 && year % 4 == 0) { isLeapYear = TRUE; mDays[2] = 29; }else{ mDays[2] = 28; } int res = 0; for (int i = 0; i < month; i++) { res += mDays[i]; } printf("%d\n", res + day); } }