#45472: c++ answer


chbel5460@gmail.com (玲君陳)

學校 : 臺北市私立復興實驗高級中學
編號 : 276052
來源 : [36.228.195.113]
最後登入時間 :
2024-10-19 21:09:00
c350. “綠白黃” 四校聯課 | From: [36.228.221.173] | 發表日期 : 2025-03-05 23:11

#include <iostream>
using namespace std;

int main(){
    int n, k, w;
    // There may be multiple test cases.
    while(cin >> n >> k >> w){
        int original = n; // Save the original count
        int extraSum = 0;
        
        // While we have enough phones for an exchange
        while(n >= k){
            int groups = n / k;     // How many groups we can make
            int newPhones = groups * w;  // Extra phones we get in this round
            extraSum += newPhones;       
            // Update: new available phones = new extra phones + remainder phones
            n = newPhones + n % k;  
        }
        
        // The total is the original phones plus all extra phones obtained.
        cout << original + extraSum << "\n";
    }
    return 0;
}

 
ZeroJudge Forum