题解 | #今年的第几天?#
今年的第几天?
https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d
#include <bits/stdc++.h> using namespace std; bool run(int year){ if(year % 4 == 0 and year % 100 !=0 or year % 400 == 0) return true; else return false; } int main(){ int year,month,day; int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; while(cin >> year >> month >> day){ if(run(year)) months[2] = 29; else months[2] = 28; int count = 0; for(int i = 1; i <= month-1; i ++){ count = count + months[i]; } cout << count + day << endl; } }
简单题,注意闰年的判断条件
year % 4 == 0 and year % 100 !=0 or year % 400 = 0
#算法#