OpenGenus / cosmos

World's largest Contributor driven code dataset | Used in Quark Search Engine, @OpenGenus IQ, OpenGenus Visual Project
http://internship.opengenus.org
GNU General Public License v3.0
13.55k stars 3.67k forks source link

Hackerrank Chocolate Feast Solution in C #5409

Open ritish099 opened 4 years ago

ritish099 commented 4 years ago

This is a(n):

Details:

Little Bobby loves chocolate. He frequently goes to his favorite 5 & 10 store, Penny Auntie, to buy them. They are having a promotion at Penny Auntie. If Bobby saves enough wrappers, he can turn them in for a free chocolate.

For example, Bobby has n = 15 to spend on bars of chocolate that cost c = 3 each. He can turn in m = 2 wrappers to receive another bar. Initially, he buys 5 bars and has 5 wrappers after eating them. He turns in 4 of them, leaving him with 1, for 2 more bars. After eating those two, he has 2 wrappers, turns in 2 leaving him with 1 wrapper and his new bar. Once he eats that one, he has 1 wrappers and turns them in for another bar. After eating that one, he only has wrapper, and his feast ends. Overall, he has eaten 5 + 2 + 1 + 1 = 9 bars.

ShubhamRattra commented 4 years ago

I would like to solve this.

ritish099 commented 4 years ago

Its already done in C

ShubhamRattra commented 4 years ago

ooh ok 😅👍