1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include <stdio.h> class Solution { public: int numWaterBottles(int numBottles, int numExchange) { int exchange_bootles = -1; int total_water = 0; do { exchange_bootles = numBottles / numExchange; numBottles = numBottles % numExchange; numBottles += exchange_bootles; total_water += exchange_bootles * numExchange;
} while (numBottles >= numExchange); total_water += numBottles; return total_water; } };
|