2012/02/28

[zerojudge] d069 格瑞哥里的煩惱 (t 行版)

題目:https://zerojudge.tw/ShowProblem?problemid=d069
說明:與 d067 一樣的判斷方式,只有輸入多需要一迴圈來處理。

Java 版
import java.util.Scanner;
 
public class D069 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = Integer.parseInt(in.nextLine());
        for(int i = 0; i < k ;i++) {
            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)
k = int(input())
for i in range(k):
    a = int(input())
    if ((a % 4 == 0) and (a % 100 != 0)) or (a % 400 == 0):
        print('a leap year')
    else:
        print('a normal year')

沒有留言:

張貼留言