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