UVa 11689 – Soda Surpler
Tim is a person who loves to drink soda very much. Since he doesn't have money, the only way he can drink soda is by collecting empty soda bottles and then taking them to recycle for money to buy new soda to drink. In addition to the empty bottles he drinks himself, Tim also goes out to collect empty bottles that others have finished drinking. One day, he is very thirsty, and he wants to drink as much soda as possible until he can't get any more bottles.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line of input contains an integer N, indicating how many sets of test data follow. Each set of test data consists of a single line containing three integers: E, F, and C. E (0 <= E < 1000) represents the number of empty bottles Tim initially has, F (0 <= F < 1000) represents the number of empty bottles Tim collects from the street on that day, and C (1 < C < 2000) represents how many empty bottles can be exchanged for a new bottle of soda. | For each set of test data, output a single line representing how many bottles of soda Tim can drink. |
2 9 0 3 5 5 2 | 4 9 |
Thought Process
You can use a while loop to make the check each time. The initial value of all empty bottles is E+F. It's important to note that after exchanging for a bottle of soda, one empty bottle is consumed, so the count of empty bottles should increase by 1.
Sample Code-ZeroJudge A536: Soda Surpler
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
for (int i = 0; i<N; i++)
{
int E, F, C;
cin >> E >> F >> C;
int total = E+F;
int ans = 0;
while (total >= C)
{
total -= C;
total++;
ans++;
}
cout << ans << "\n";
}
}
//ZeroJudge A536
//Dr. SeanXD