在一行中输入一个整数
,满足
。
输出一个字符串,若
为闰年,输出 "yes"(不含双引号);否则输出 "no"(不含双引号)。
2000
yes
能被
整除,因此是闰年。
1900
no
能被
整除但不能被
整除,因此不是闰年。
//能被4整除但不能被100整除的年份是闰年,能被400整除的年份也是闰年。
//2024年是闰年,因为它可以被4整除,但不能被100整除。
//1900年不是闰年,因为它可以被100整除,但不能被400整除。
//1600年是闰年,可以被4整除,也能被100整除,但它同时也能被400整除。
#include <stdio.h>
int main()
{
int a = 0;
scanf("%d", &a);
if(a % 400 == 0)
{
printf("yes\n");
}
else
{
if(a % 4 == 0 && a % 100 != 0)
{
printf("yes\n");
}
else {
printf("no\n");
}
}
return 0;
} #include <stdio.h>
int main() {
int a;
scanf("%d",&a);
printf("%s\n", ((a%400==0)||((a%4==0)&&(a%100)))? "yes":"no");
return 0;
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0)) {
System.out.println("yes");
}else {
System.out.println("no");
}
}
}
} #include <stdio.h>
#include <stdbool.h>
static bool is_leap_year(int n)
{
if ((n % 400 == 0) ||
(n % 4 == 0 && n % 100 != 0))
{
return true;
}
return false;
}
int main() {
int n = 0;
scanf("%d", &n);
printf("%s", is_leap_year(n) ? "yes" : "no");
return 0;
}