【題解】ZeroJudge d673: 11608 – No Problem

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

#include <iostream>
using namespace std;

int main() {
    int S, Case = 1;
    int a[12], b[12];
    while (cin >> S){
        if (S < 0) break;
        for (int i = 0; i < 12; i++){
            cin >> a[i];
        }
        for (int i = 0; i < 12; i++){
            cin >> b[i];
        }
        cout << "Case " << Case++ << ":\n";
        for (int i = 0; i < 12; i++){
            if (b[i] <= S){
                cout << "No problem! :D\n";
                S -= b[i];
            } else {
                cout << "No problem. :(\n";
            }
            S += a[i];
        }
    }
    return 0;
}

Python code (credit: Amy Chou)

TC = 1
while True:
    S = int(input())
    if S < 0:
        break
    
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    print(f"Case {TC}:")
    TC += 1
    
    for i in range(12):
        if b[i] <= S:
            print("No problem! :D")
            S -= b[i]
        else:
            print("No problem. :(")
        S += a[i]
分享本文 Share with friends