說明:與 d067 一樣的判斷方式,使用迴圈並改變輸出。
Java 版
import java.util.Scanner;
public class D072 {
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("Case " + (i+1) + ": a leap year");
else
System.out.println("Case " + (i+1) + ": 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('Case {}: a leap year'.format(i+1))
else:
print('Case {}: a normal year'.format(i+1))
沒有留言:
張貼留言