#include<iostream>
using namespace std;
struct Year
{
int year;
int month;
int day;
};
int main()
{
Year year1;
cin >> year1.year;
cin >> year1.month;
cin >> year1.day;
int num;//记录第几天
int num1;//记录有31天的月
num = (year1.month-1) * 30;//先全部按30算,-1是除掉本月
if ((year1.month - 1) % 2 != 0||year1.month==9||year1.month==11)//判断8 月 10月 1 3 5 7 8 10
{
num1 = (year1.month-1) / 2 + 1;//月份是偶数
}
else
{
num1 = (year1.month-1) / 2;//月份是奇数
}
if ((year1.year % 4 ==0 && year1.year % 100 !=0) ||(year1.year % 100 == 0&& year1.year % 400 ==0))//判断是否闰年,闰年2月有29天不是28天
{
num = num1 + num - 1;
}
else {
num = num1 + num - 2;
}
num = num + year1.day;//最后+本月的天数
cout << num;//2023.3.6有65天 2020.3.6闰年有66天
return 0;
}
结构体,输入年月日,计算该日是本年中的第几天
于 2023-03-06 21:23:34 首次发布