题解 | #今年的第几天?#
今年的第几天?
https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d
//利用数组存储每月日数,即空间换时间 #include "stdio.h" int main(){ int year,mouth,day; int map[13] = {0,31,28,31,30,31,30, 31,31,30,31,30,31}; while (scanf("%d%d%d",&year,&mouth,&day)!=EOF) { bool special;int sum = 0; if(year%400==0 || (year%4 == 0 && year%100 != 0)){ special = true;//为闰年 if(mouth > 2) ++sum; } for(int i = 1;i <= mouth-1;++i){ sum = sum + map[i]; } sum += day; printf("%d\n",sum); } }