题解 | 计算日期到天数转换
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
xiao hai mo ji ga
#include <iostream> #include <vector> using namespace std; int main() { int year, month, day; cin >> year >> month >> day; vector<int> days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool is_leap_year = (year%4 == 0 && year%100) || year%400 == 0; if(is_leap_year) days[1] = 29; int ans = 0; for(int i = 0; i < month - 1; ++i) { ans += days[i]; } ans += day; cout << ans << endl; return 0; }