JulianJulianov

The Hunting Games

Jul 7th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 KB | None | 0 0
  1. The Hunting Games
  2. A group of friends have decided to participate in a game called "The Hunting Games". The first stage of the game is to gather some supplies. They have a list and your job is to help them follow it and make the needed calculations.
  3. Write a program that calculates the needed provisions for a quest in the woods.
  4. First you will receive the days of the adventure, the count of the players and the group’s energy. Afterwards, you will receive the following provisions per day for one person:
  5.  Water
  6.  Food
  7. The group calculates how many supplies they’d need for the adventure and take that much water and food.
  8. Every day they chop wood and lose a certain amount of energy. For each of the days, you are going to receive the energy loss from chopping wood. The program should end If the energy reaches 0 or less.
  9. Every second day they drink water, which boosts their energy with 5% of their current energy and at the same time drops their water supplies by 30% of their current water.
  10. Every third day they eat, which reduces their food supplies by the following amount:
  11. {currentFood} / {countOfPeople} and at the same time raises their group’s energy by 10%.
  12. The chopping of wood, the drinking of water, and the eating happen in the order above.
  13. If they have enough energy to finish the quest, print the following message:
  14. "You are ready for the quest. You will be left with - {energyLevel} energy!"
  15. If they run out of energy print the following message and the food and water they were left with before they ran out of energy:
  16. "You will run out of energy. You will be left with {food} food and {water} water."
  17. Input / Constraints
  18. • On the 1st line, you are going to receive a number N - the days of the adventure – an integer in the range [1100]
  19. • On the 2nd line – the count of players – an integer in the range [01000]
  20. • On the 3rd line - the group’s energy – a real number in the range [1 - 50000]
  21. • On the 4th line – water per day for one person – a real number [0.001000.00]
  22. • On the 5th line – food per day for one person – a real number [0.001000.00]
  23. • On the next N lines – one for each of the days – the amount of energy loss– a real number in the range [0.00 - 1000]
  24. • You will always have enough food and water.
  25. Output
  26. "You are ready for the quest. You will be left with - {energyLevel} energy!"
  27. if they have enough energy
  28. "You will run out of energy. You will be left with {food} food and {water} water."
  29. • All of the real numbers should be formatted to the second digit after the decimal separator
  30. Examples
  31. Input          Output
  32. 10             You are ready for the quest. You will be left with - 658.72 energy!
  33. 7
  34. 5035.5
  35. 11.3
  36. 7.2
  37. 942.3
  38. 500.57
  39. 520.68
  40. 540.87
  41. 505.99
  42. 630.3
  43. 784.20
  44. 321.21
  45. 456.8
  46. 330
  47. Comments
  48. The days are 10 and the players are 7. The energy of the whole group is 5035.5. We receive the water and food and we can calculate the needed amount of both for the whole quest:
  49. 10 * 7 * 11.3 – total water = 791
  50. 10 * 7 * 7.2 – total food = 504
  51. Afterwards, for each of the days you have to calculate the energy loss. On each day you receive energy loss and you have to subtract it. On the first day it is:
  52. 5035.5942.3 = 4093.2
  53. On every second day we add the energy boost from the drank water, which is 5% of the current energy and subtract the amount from the total water. The first time we reach a second day, the energy will become 3772.26 and the water will become 553.7. The first time we reach a third day, we have to boost the energy with 10% and reduce the food supplies and the energy will become - 3576.74 and the food 432. Make all of the calculations and in the end, you must have 658.77 energy left and 132.94 water and 317.39 food left.
  54.  
  55.  
  56. Input          Output
  57. 12             You will run out of energy. You will be left with 229.17 food and 118.59 water.
  58. 6
  59. 4430
  60. 9.8
  61. 5.5
  62. 620.3
  63. 840.2
  64. 960.1
  65. 220
  66. 340
  67. 674
  68. 365
  69. 345.5
  70. 212
  71. 412.12
  72. 258
  73. 496
  74. using System;
  75.                    
  76. public class Program
  77. {
  78.     public static void Main()
  79.     {
  80.             var days = int.Parse(Console.ReadLine());
  81.             var players = int.Parse(Console.ReadLine());
  82.             var groupEnergy = double.Parse(Console.ReadLine());
  83.             var waterPerson = double.Parse(Console.ReadLine());
  84.             var foodPerson = double.Parse(Console.ReadLine());
  85.  
  86.             var totalWater = days * players * waterPerson;
  87.             var totalFood = days * players * foodPerson;
  88.             for (int i = 1; i <= days; i++)
  89.             {
  90.                 var energyLoss = double.Parse(Console.ReadLine());
  91.                 groupEnergy -= energyLoss;
  92.  
  93.                 if (groupEnergy <= 0)
  94.                 {
  95.                     break;
  96.                 }
  97.                 if (i % 2 == 0)
  98.                 {
  99.                     totalWater -= 0.30 * totalWater;
  100.                     groupEnergy += 0.05 * groupEnergy;
  101.                 }
  102.                 if (i % 3 == 0)
  103.                 {
  104.                     totalFood -= totalFood / players;
  105.                     groupEnergy += 0.10 * groupEnergy;
  106.                 }
  107.             }
  108.             if (groupEnergy > 0)
  109.             {
  110.                 Console.WriteLine($"You are ready for the quest. You will be left with - {groupEnergy:F2} energy!");
  111.             }
  112.             else
  113.             {
  114.                 Console.WriteLine($"You will run out of energy. You will be left with {totalFood:F2} food and {totalWater:F2} water.");
  115.             }
  116.     }
  117. }
Add Comment
Please, Sign In to add comment