We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Yeah! You are right and the description is easy. I sloved this problem with the same way. The following is my AC code :)
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t,n,c,m;
cin>>t;
while(t--){
cin>>n>>c>>m;
int answer=0;
// Computer answer(the total of chocolates Bob eats)
// answer consists of two parts: directly buy with money and exchange with wrapper
int answer1 = n / c; // the number of buying with money
answer += answer1;
int answer2 = 0; // the number of exchanging with wrapper
int wrapper = answer1 / m; // the number of first exchange with wrapper
int remain = answer1 % m; // the number of first remain wrapper
answer2 += wrapper;
int available = wrapper + remain;
while (available / m != 0) {
wrapper = available / m;
remain = available % m;
answer2 += wrapper;
available = wrapper + remain;
}
answer += answer2;
cout<<answer<<endl;
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Chocolate Feast
You are viewing a single comment's thread. Return to all comments →
Yeah! You are right and the description is easy. I sloved this problem with the same way. The following is my AC code :)