JulianJulianov

Every 3rd or 5th day

May 29th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.97 KB | None | 0 0
  1. Spring Vacation Trip
  2. A group of friends decide to go to a trip for a few days during spring vacation. They have a certain budget. Your task is to calculate their expenses during the trip and find out if they are going to have enough money to finish the vacation.
  3. Create a program that calculates travelling expenses by entering the following information:
  4. -   Days of the vacation
  5. -   Budget - its for the whole group
  6. -   The count of people
  7. -   Fuel per kilometer – the price for fuel that their car consumes per kilometer
  8. -   Food expenses per person
  9. -   Hotel room price for one night – again, for one person
  10. If the group is bigger than 10, they receive a 25% discount from the total hotel expenses.
  11. Every day, they travel some distance and you have to calculate the expenses for the travelled kilometers.
  12. Every third and fifth day, they have some additional expenses, which are 40% of the current value of the expenses.
  13. Every seventh day, their expenses are reduced, because they withdraw (receive) a small amount of money – you can calculate it by dividing the amount of the current expenses by the group of people.
  14. If the expenses exceed the budget at some point, stop calculating and print the following message:
  15. "Not enough money to continue the trip"
  16. If the budget is enough:
  17. "You have reached the destination. You have {money}$ budget left."
  18. Print the result formatted 2 digits after the decimal separator.
  19. Input / Constraints
  20. • On the 1st line, you are going to receive the days of the trip – an integer in the range [1100]
  21. • On the 2nd line – the budget – a real number in the range [0.001000000.00]
  22. • On the 3rd line - the group of people – an integer in the rang [1 - 50]
  23. • On the 4th line – the price for fuel per kilometer – a real number [0.0020.00]
  24. • On the 5th line – food expenses per person for a day – a real number [0.0050.00]
  25. • On the 6th line – the price for a room for one night per person – a real number [0.001000.00]
  26. • On the next n lines – one for each of the days – the travelled distance in kilometers per day– a real number in the range [0.00 - 1000]
  27. Output
  28. "Not enough money to continue the trip. You need {money}$ more."
  29. if the budget is not enough
  30. "You have reached the destination. You have {money}$ budget left."if it’s enough.
  31. Print the result formatted 2 digits after the decimal separator.
  32. Examples
  33. Input   Output                            Comments
  34. 7                                         We receive the days of the vacation, the budget, the group, the consumed fuel per
  35. 12000   You have reached the destination. kilometer, the food expenses and the price for a hotel room for one night.
  36. 5       You have 5083.48$ budget left.    We must calclate the food expenses: 10 * 5 * 7 = 350
  37. 1.5                                       And the price for the hotel for all of the nights: 20 * 5 * 7 = 700
  38. 10                                        The curent expenses are 1050. For each day, we have to calculate the consumed
  39. 20                                        fuel – {travelledDistance} * 1.5 On every 3rd  and 5th  day we add the additional expenses:
  40. 512                                 0.4 * {currentExpenses} On every 7th day, they receive some money:{currentExpense} /{groupOfPeople}
  41. 318                                       After we have added the fuel expenses for each day and made the other calculations,
  42. 202                                       the expenses have reached 8645.652. When we divide them by the group (5),
  43. 154                                       the result is 1729.1304, so we have to reduce the expenses by that sum.
  44. 222                                       The expenses become 6916.5216. The budget is enough, so the result is:
  45. 108                                       "You have reached the destination. You have 5083.48$ budget left."
  46. 123      
  47.  
  48.  
  49. 10      Not enough money to continue the trip. You need 465.79$ more.
  50. 20500
  51. 11
  52. 1.2
  53. 8
  54. 13
  55. 100
  56. 150
  57. 500
  58. 400
  59. 600
  60. 130
  61. 300
  62. 350
  63. 200
  64. 300
  65.  
  66. using System;
  67.  
  68. public class Program
  69. {
  70.     public static void Main()
  71.     {
  72.            var daysOfTheTrip = int.Parse(Console.ReadLine());
  73.             var theBudget = double.Parse(Console.ReadLine());
  74.             var theGroupOfPeople = int.Parse(Console.ReadLine());
  75.             var priceFuelKm = double.Parse(Console.ReadLine());
  76.             var foodPersonDay = double.Parse(Console.ReadLine());
  77.             var priceRoomNightPerson = double.Parse(Console.ReadLine());
  78.  
  79.             if (theBudget == 0)
  80.             {
  81.                 return;
  82.             }
  83.             var foodExpenses = daysOfTheTrip * foodPersonDay * theGroupOfPeople;
  84.             var priceHotel = priceRoomNightPerson * theGroupOfPeople * daysOfTheTrip;
  85.            
  86.             if (theGroupOfPeople > 10)
  87.             {
  88.                 priceHotel *= 0.75; //Или priceHotel -= 0.25 * priceHotel;
  89.             }
  90.             var expenses = foodExpenses + priceHotel;
  91.             for (int i = 1; i <= daysOfTheTrip; i++)
  92.             {
  93.                 var travelledDistanceKmDay = double.Parse(Console.ReadLine());
  94.                 var expensesFuel = travelledDistanceKmDay * priceFuelKm;
  95.                 expenses += expensesFuel;
  96.                 if (i % 3 == 0 || i % 5 == 0) //Капанче! Така на 15-ия ден ще има само веднъж разходи!
  97.                 {
  98.                     expenses += 0.40 * expenses;
  99.                 }
  100.                 if (i % 7 == 0)
  101.                 {
  102.                     expenses -= expenses / theGroupOfPeople;
  103.                 }
  104.                 if (theBudget < expenses)
  105.                 {
  106.                     Console.WriteLine($"Not enough money to continue the trip. You need {expenses - theBudget:F2}$ more.");
  107.                     break;
  108.                 }
  109.                 else if (daysOfTheTrip == i)
  110.                 {
  111.                     Console.WriteLine($"You have reached the destination. You have {theBudget - expenses:F2}$ budget left.");
  112.                 }
  113.             }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment