Since Ivancho is very whimsical he decides the kilograms of flour needed to make a cake and the number of cakes he wants, every day. First thing Ivancho needs for his cakes is flour, however it turns out there is only one provider of flour in the city and he can only deliver a specific amount of kilograms of flour per day, luckily though he’s a friend of Ivancho’s father so Ivancho doesn’t have to pay for the flour. The second thing Ivancho likes the most after cakes is truffles, so Ivancho decided he wants all his cakes to have truffles in them, as much truffles as he can buy, which he will then divide evenly amongst all cakes he can make that day, but since truffles are so rare the amount of truffles available and the price for a truffle changes each day. Lastly Ivancho has to make a profit, so he decided that the price at which he will sell one cake will be equal to the price of the ingredients for one cake increased by 25%.
Your task is to write a program to calculate the amount of cakes that Ivancho can make that day and the price for one cake.
You’ll be given some numbers. The number of cakes Ivancho wants that day, the kilograms of flour needed to make one cake, the kilograms of flour which the provider can give you, the amount of truffles you can buy and the price for each truffle.
If Ivancho has enough flour to make the amount of cakes he wants, he will make exactly that amount, the leftover flour will be discarded and you should print on the console “All products available, price of a cake: {price of one cake}”.
Alternatively if there is not enough flour you should round down the number of cakes that can be produced to a whole number (since Ivancho only wants whole cakes) and print them on the console in the format “Can make only {number of cakes that can be produced} cakes, need {kilograms of flour needed} kg more flour” where kilograms of flour needed is the difference between the kilograms of flour required to make the amount of cakes Ivancho wanted and the kilograms of flour available.
Input
The input data should be read from the console. It consists of five input values, each at a separate line:
- The number n – amount of cakes Ivancho wants.
- The number c – kilograms of flour needed to make one cake.
- The number f – kilograms of flour available.
- The number t – amount of truffles available.
- The number p – price of one truffle.
The input data will always be valid and in the format described. There is no need to check it explicitly.
Output
The output should be printed on the console.
- If there isn’t enough flour to make the amount of cakes Ivancho wants print on the console:
- “Can make only {number of cakes that can be produced} cakes, need {kilograms of flour needed} kg more flour”
- If there is enough flour:
- “All products available, price of a cake: {price of one cake}”
- The number of cakes that can be produced must be a whole number; the price of the cake and the kilograms of flour needed must be rounded to two digits after the decimal point.
Constraints
- The number n will be a valid integer in the range [1 … 18 446 744 073 709 551 615]
- The number c will be a floating-point numbers in the range [0 … 7.9 x 1028].
- The numbers f, t and p will be valid integers in the range [0 ... 4 294 967 295].
- Allowed working time for your program: 0.25 seconds.
- Allowed memory: 16 MB.
Examples
Here is the solution, my friend:
using System; class Task1 { static void Main() { decimal cakesWants = decimal.Parse(Console.ReadLine());//The number n – amount of cakes Ivancho wants. decimal kgFlour = decimal.Parse(Console.ReadLine());//The number c – kilograms of flour needed to make one cake. decimal flourAv = decimal.Parse(Console.ReadLine());//The number f – kilograms of flour available. decimal trufflesAv = decimal.Parse(Console.ReadLine());//The number t – amount of truffles available. decimal priceTruffles = decimal.Parse(Console.ReadLine());//The number p – price of one truffle. decimal howManyCakes = flourAv / kgFlour; decimal trufflesCost = trufflesAv * priceTruffles; decimal cakePrice = (trufflesCost / cakesWants) * 1.25m; decimal howManyCakesRound = Math.Floor(howManyCakes); decimal totalFlour = cakesWants * kgFlour; decimal kgNeeded = totalFlour - flourAv; if (howManyCakes >= cakesWants) { Console.WriteLine("All products available, price of a cake: {0:f2}", cakePrice); } else if (howManyCakesRound < cakesWants) { Console.WriteLine("Can make only {0} cakes, need {1:f2} kg more flour", howManyCakesRound, kgNeeded); } } }