Chocolate Feast code in C#

Little Bob loves chocolate, and he goes to a store with $N in his pocket. The price of each chocolate is $C. The store offers a discount: for every M wrappers he gives to the store, he gets one chocolate for free. How many chocolates does Bob get to eat?

Input Format:
The first line contains the number of test cases, T.
T lines follow, each of which contains three integers, N, C, and M.

Output Format:
Print the total number of chocolates Bob eats.

Constraints:
1T1000
2N105
1CN
2MN

Sample input

3
10 2 5
12 4 4
6 2 2

Sample Output

6

3

5

 

class Chocklate_Feast_Hackerrank
{
static void Main(String[] args)
{
int cases = int.Parse(Console.ReadLine());
for (int i = 0; i < cases; i++)
{
int[] temp = Console.ReadLine().Split(‘ ‘).Select(x => int.Parse(x)).ToArray<int>();
int total = temp[0] / temp[1];
int wrappers = total;
while (wrappers >= temp[2])
{
int temp2 = wrappers / temp[2];
total += temp2;
wrappers = (wrappers – (temp2 * temp[2])) + temp2;
}
Console.WriteLine(total);
}
Console.ReadLine();
}
}


		
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s