2012/02/23

[zerojudge] d067 格瑞哥里的煩惱 (1 行版)

題目:https://zerojudge.tw/ShowProblem?problemid=d067
說明:這題與 a004 應該是一樣的,只是將結果輸出變成英文。

Java 版
import java.util.Scanner;

public class D067 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int a = Integer.parseInt(in.nextLine());
            if(((a % 4) == 0 && (a % 100) != 0) || (a % 400) == 0)
                System.out.println("a leap year");
            else
                System.out.println("a normal year");
        }
    }
}
Python 版 (2022.07)
while True:
    try:
        a = int(input())
        if ((a % 4 == 0) and (a % 100 != 0)) or (a % 400 == 0):
            print('a leap year')
        else:
            print('a normal year')
    except:
        break

沒有留言:

張貼留言