真经题解 | A368.完成闰年判定函数
2024-08-05 19:53:05
发布于:浙江
题目分析
其实这道题很简单,我给大家看一道题目,大家应该就都会做了。
要是不会做也没有关系哦
传送门
其实很简单,和上面的传送门里面的题目一样,你只要会做上面的闰年判断就行了。
闰年判断规则
闰年的判断规则主要依据年份是否能被4整除,同时考虑是否能被100整除以及是否能被400整除。
对于普通年份,如果它能被4整除且不能被100整除,那么这一年就是闰年。例如,2024年能被4整除且不能被100整除,因此2024年是闰年。
对于世纪年份,即年份能被100整除的年份,要进一步判断它是否能被400整除。如果能被400整除,那么这一年也是闰年。例如,2000年能被400整除,因此2000年是闰年。
此外,对于数值很大的年份,如果它能被3200整除且能被172800整除,那么这一年也是闰年。例如,172800年能同时被3200和172800整除,因此172800年是闰年。
这些规则确保了闰年的设定能够适应不同的时间尺度,从普通年份到世纪年份,再到极端的数值大的年份,都有明确的判断标准。闰年的设立是为了弥补因人为历法规定造成的年度天数与地球实际公转周期的时间差
答案
#include<iostream>
using namespace std;
bool is_leap(int a){
if(a % 4 == 0 && a % 100 != 0){
return true;
}
if(a % 400 == 0){
return true;
}
else{
return false;
}
}
int main() {
int n;
cin >> n;
if(is_leap(n)) cout << "Y" << endl;
else cout << "N" << endl;
return 0;
}
Topic analysis
Actually, this question is very simple. Let me show you a question, and everyone should be able to solve it.
It's okay if you can't do it
[Portal]( https://www.acgo.cn/problemset/info/298 )
It's actually quite simple, just like the questions in the portal above, as long as you know how to make leap year judgments.
Leap year judgment rules
The judgment rule for leap years mainly depends on whether the year can be divided by 4, while considering whether it can be divided by 100 and 400.
For a regular year, if it can be divided by 4 and cannot be divided by 100, then that year is a leap year. For example, 2024 can be divided by 4 and cannot be divided by 100, so 2024 is a leap year.
For century years, which are years that can be divided by 100, it is necessary to further determine whether they can be divided by 400. If it can be divided by 400, then this year is also a leap year. For example, the year 2000 can be divided by 400, so it is a leap year.
In addition, for a year with a large numerical value, if it can be divided by 3200 and 172800, then that year is also a leap year. For example, 172800 can be divided by both 3200 and 172800, so 172800 is a leap year.
These rules ensure that the setting of leap years can adapt to different time scales, from ordinary years to century years, and even to extremely high numerical years, with clear criteria for judgment. The establishment of leap years is to compensate for the time difference between the annual number of days caused by human calendar regulations and the actual orbital period of the Earth
Answer:
#include<iostream>
using namespace std;
bool is_leap(int a){
if(a % 4 == 0 && a % 100 != 0
return true;
}
if(a % 400 == 0){
return true;
}
else{
return false;
}
}
int main() {
int n;
cin >> n;
if(is_leap(n)) cout << "Y" << endl;
else cout << "N" << endl;
return 0;
}
全部评论 3
顶
2024-08-05 来自 浙江
0顶
2024-08-05 来自 浙江
0顶
2024-08-05 来自 浙江
0
有帮助,赞一个