题解 | #今年的第几天?#
今年的第几天?
https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d
#include <cstdio> int main(){ int year,mon,day; int totalday[13] = {0}; int monday[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; for (int i = 2; i <= 12; ++i) { totalday[i] = totalday[i - 1] + monday[i - 1]; } while (scanf("%d%d%d",&year,&mon,&day) != EOF){ bool isyear = year % 400 == 0 || year % 100 != 0 && year % 4 == 0; if (isyear == true && mon >= 3){ printf("%d\n",totalday[mon] + 1 + day); } else{ printf("%d\n",totalday[mon] + day); } } }