#include<stdio.h>
//代码的最高境界,是思想与智慧的精神产物。
bool Is_Leapyear(int year)
{
return year % 4 == 0 && year % 100!=0||year % 400 == 0;
}
int Get_MY_Day(int year, int month)
{
static const int days[] = { 29,31,28,31,30,31,30,31,31,30,31,30,31 };
// 0 1 2 3 4 5 6 7 8 9 10 11 12
if (month == 2 && Is_Leapyear(year))
{
month = 0;
}
return days[month];
}
int Get_sum(int year, int month, int day)
{
if (year < 1)return -1; //对于传到的形参一定要检查其合法性
if (month < 1 || month>12)return -2;
if (day<1 || day>Get_MY_Day(year, month))return -3;
int sum = 0;
for (int i = 1; i < month; i++)
{
sum += Get_MY_Day(year, i);
}
return sum+day;
}
int main()
{
int year;
int month;
int day;
scanf_s("%d %d %d", &year, &month, &day);
printf("%d\n",Get_sum(year,month,day));
return 0;
}
2021-09-13数组_1
最新推荐文章于 2024-08-28 09:50:23 发布