【題解】ZeroJudge d072: 格瑞哥里的煩惱 (Case 版)

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d072

#include <iostream>
using namespace std;

int main() {
    int y, n;
    
    cin >> n;
    for (int TC = 1; TC <= n; TC++) {
        cin >> y;
        cout << "Case " << TC << ": ";
        if ((y % 4 == 0 && y % 100 != 0) || (y % 400) == 0)
            cout << "a leap year\n";
        else
            cout << "a normal year\n";
    }
    return 0;
}

Python code (credit: Amy Chou)

n = int(input())
for TC in range(1, n+1):
    print(f"Case {TC}: ", end="")
    y = int(input())
    if ((y % 4 == 0) and (y % 100 != 0)) or (y % 400 == 0):
        print("a leap year")
    else:
        print("a normal year")
分享本文 Share with friends