题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include <iostream>
using namespace std;
int main() {
int a, b;
int day;
int arr1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int arr2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
while (cin >> a >> b) { // 注意 while 处理多个 case
cin>>day;
int sum=0;
if((a%4==0&&a%100!=0)||(a%400==0))
{
for(int i=0;i<b-1;i++)//闰年
{
sum+=arr2[i];
}
sum+=day;
}
else
{
for(int i=0;i<b-1;i++)//非闰年
{
sum+=arr1[i];
}
sum+=day;
}
cout << sum << endl;
}
}
// 64 位输出请用 printf("%lld")
查看34道真题和解析