首页 >

判断闰年

n = int(input())
if n % 400 ==0 or (n %4 ==0 and n%100 != 0):
    print("yes")
else:
    print("no")
#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n % 400 == 0 || n % 4 == 0 && n % 100 != 0) cout << "yes" << endl;
    else cout << "no" << endl;
}

发表于 2022-02-26 14:07:32 回复(2)
n = int(input())
print('yes' if n % 400 == 0 or (n % 4 ==0 and n %100 != 0) else 'no' )
发表于 2025-07-10 09:59:47 回复(0)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >>a;
    if(a%4==0 && a%100!=0){
        cout<<"yes"<<endl;
           
    }
    else if(a%400==0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}
发表于 2024-11-25 18:48:51 回复(0)
//能被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;
}

发表于 2024-01-28 21:56:09 回复(0)
#include <stdio.h>
//闰年的判断方法可以简化为:
// 1. 能被4整除但不能被100整除的年份是闰年
// 2. 能被400整除的年份也是闰年
int main() {
    int n=0;
    scanf("%d",&n);
    if((n%4==0&&n%100!=0)||(n%400==0))
    {
        printf("yes");
    }
    else {
    {
        printf("no");
    }
    }
    return 0;
}

发表于 2024-01-13 10:15:36 回复(0)
n=int(input())
if (n%4==0 and n%100!=0)&nbs***bsp;n%400==0:
    print('yes')
else:
    print('no')    

发表于 2023-01-18 09:44:35 回复(0)
year= int(input())
if year % 400 == 0:
    print('yes')
elif (year % 4 == 0) and (year % 100 != 0):
    print('yes')
else:
    print('no')
发表于 2022-03-17 19:16:16 回复(1)
还是用函数表达比较舒适。
#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;
}


发表于 2025-08-06 17:05:40 回复(0)
n = int(input())
if 1 <= n <= 2018:
    if (n % 4 == 0 and n % 100 != 0) or (n % 400 == 0):
        print("yes")
    else:
        print("no")
else:
    print("请输入一个1<=n<=2018的正整数")
发表于 2025-07-24 10:45:32 回复(0)
use std::io;

fn main() {
    let mut stdin = String::new();

    io::stdin()
        .read_line(&mut stdin)
        .expect("");

    let n:i64 = stdin
        .trim()
        .parse()
        .expect("");

    if n % 400 == 0 {
        println!("yes");
    } else if n % 4 == 0 && n % 100 != 0 {
        println!("yes");
    } else {
        println!("no");
    }

}
发表于 2025-07-19 13:48:57 回复(0)
n = int(input())
if n % 400 ==0 or (n %4 ==0 and n%100 != 0):
    print("yes")
else:
    print("no")
发表于 2025-07-17 11:48:17 回复(0)
using System;
public class Program {
    public static void Main() {
        string[] input = Console.ReadLine().Split();
        int n = int.Parse(input[0]);
        if(n%400==0 || n%4==0 && n%100!=0)
        {
            Console.WriteLine("yes");
        }else
        {
            Console.WriteLine("no");
        }
    }
}
发表于 2025-07-16 00:42:18 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a;
    cin >> a;
    if(a %400 == 0){
        cout << "yes";
    }else if( a%4 == 0 && a%100 !=0) {
        cout << "yes";
    } else {
        cout << "no";
    }
}

发表于 2025-07-14 11:42:31 回复(0)
jdk8以后的时间类新加了isleap方法可以直接判断是否是闰年。
发表于 2025-07-13 23:47:14 回复(0)
n = int(input())

if n % 400 == 0:
    print ("yes")
elif (n % 4 == 0) & (n % 100 !=0):
    print ("yes")
else:
    print("no")
发表于 2025-07-13 05:50:48 回复(0)
java 有手就行
import java.util.Scanner;
import java.time.LocalDate;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner src = new Scanner(System.in);
        int a = src.nextInt();
        LocalDate ld = LocalDate.of(a,3,1);




        LocalDate ld2 = ld.minusDays(1);
        int day = ld2.getDayOfMonth();
        if(day == 29){
            System.out.print("yes");
        }
        else{
            System.out.print("no");
        }
    }

}

发表于 2025-07-06 01:00:44 回复(0)
#include <stdio.h>

int main() {
    int n;
    while(1){
        if(scanf("%d",&n)!=1){
            while(getchar()!='\n');
            continue;
        }
        while(getchar()!='\n');
        if(n < 1 || n > 2018){
            continue;//如果输入错误就重新开始while的循环,直到正确.
        }
        if((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
        break;
    }
    return 0;
}

发表于 2025-07-01 18:02:11 回复(0)
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if(n%400==0||n%4==0&&n%100!=0)
    {
        printf("yes");
    }
    else {
        printf("no");
    }
    return 0;
}
发表于 2025-06-25 19:46:45 回复(0)
n = int(input())

if n%400==0:
    print("yes")
elif n%4==0 and n%100 != 0:
    print("yes")
else:
    print("no")
发表于 2025-06-17 16:48:32 回复(0)
#include <stdio.h>

int main()
 {
    int n = 0;
    scanf("%d", &n);

    if (n % 400 == 0)
    {
        printf("yes\n");
    }
    else if ( n % 4 == 0 && n % 100 != 0)
    {
        printf("yes\n", n);
    }
    else
    {
        printf("no\n");
    }

    return 0;
}
发表于 2025-06-08 20:58:39 回复(0)