题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include <iostream>
#include <vector>
using namespace std;
//万年历
int main() {
int year, month,day;
vector<int> month_days(12);
month_days={31,28,31,30,31,30,31,31,30,31,30,31};
while (cin >> year >> month >> day) { // 注意 while 处理多个 case
//首先根据年来确定二月天数 闰年
if(year % 400 && (year % 4==0 && year % 100!=0)){
month_days[1] = 29;
}else{
month_days[1] = 28;
}
int sum = 0;
for(int i=0;i<month-1;i++){
sum += month_days[i];
}
sum += day;
cout<<sum<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")