1 条题解

  • 0
    @ 2025-4-7 21:28:46

    C :

    #include <stdio.h>
    void main() {
        int year;
        scanf("%d", &year);
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                if (year % 400 == 0) {
                    printf("leap year\n");
                } else {
                    printf("not leap year\n");
                }
            } else {
                printf("leap year\n");
            }
        } else {
            printf("not leap year\n");
        }
    }
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
      int input;
      cin >> input;
      if((input%4 == 0 && input%100!=0) || input%400 == 0)
        cout << "leap year" << endl;
      else
        cout << "not leap year" << endl;
      return 0;
    }
    

    Pascal :

    var
       year:integer;
    begin
        readln(year);
        if (year mod 400=0)or(year mod 4=0)and(year mod 100<>0) then  writeln('leap year') else writeln('not leap year');
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner s=new Scanner(System.in);
    	int x=s.nextInt();
    	if(x%100!=0&&x%4==0||x%400==0){
    	System.out.println("leap year");
    	System.out.println();
    	}else
    	System.out.println("not leap year");
    System.out.println();
    	}
    }
    
    

    Python :

    n = input()
    if n%400==0 or (n%4==0 and n%100):
      print "leap year"
    else:
      print "not leap year"
    

    C# :

    using System;
    
    namespace C言语
    {
        class _2_3
        {
            public static bool isLeapYear(int n)
            {
                return n%4==0&&n%100!=0||n%400==0;
            }
            public static void Main()
            {
                int y;
                bool ans =true;
                y = int.Parse(Console.ReadLine());
          //      y=Convert.ToInt16(Console.ReadLine());
                ans=isLeapYear(y);
                if (ans)
                {
                    Console.WriteLine("leap year");
                }
                else
                {
                    Console.WriteLine("not leap year");
                }
                Console.ReadLine();
                return;
            }
        }
    }
    
    
    • 1

    信息

    ID
    1220
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者