【題解】ZeroJudge e834: P1.批發出貨(Wholesale)

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e834
TOI 新手同好會 歷屆考題

#include <iostream>
using namespace std;

int main() {
    int m, n;
    cin >> m;
    while (cin >> n && n){
        if (n % m) cout << m - (n % m) << "\n";
        else cout << n / m << "\n";
    }
    return 0;
}

Python code (credit: Amy Chou)

M = int(input())
lst = list(map(int, input().split()))
for x in lst[:-1]:
    if x % M == 0:
        # 若下訂量符合出貨條件,則輸出小瑜需準備多少份數的商品
        print(x // M)
    else:
        # 輸出買家需再多下訂幾件商品才符合出貨條件
        print(M - (x % M))
分享本文 Share with friends