目录
牛客HJ73 计算日期到天数转换
解析代码
牛客HJ73 计算日期到天数转换
计算日期到天数转换_牛客题霸_牛客网
解析代码
#include <iostream>
using namespace std;
int main()
{
int year = 0, month = 0, day = 0, sum = 0;
cin >> year >> month >> day;
static int arr[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int i = 1; i < month; ++i)
{
sum += arr[i];
}
// if (month > 2 && (year % 4 == 0 && year % 400 != 0))
if (month > 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
{
++sum;
}
cout << sum + day;
return 0;
}