Advertisement
knoteva

04. Best Plane Tickets

Oct 14th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BestPlaneTicket
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool flight = true;
  10.             double sum = 0;
  11.             int hour = 0;
  12.             int min = 0;
  13.             int minFlightDuration = 500; // Присвояваме максималните минути престой. Смених и името на променливата
  14.             string flightNumber = "";
  15.             //double newprice = 0; // Няма смисъл от тази променлива
  16.             string currentFlightNumber = ""; // Или string currentFlightNumber = string.Empty;
  17.  
  18.             for (int i = 1; flight == true; i++) // Може да се ползва и while(true) или while((flightNumber = Console.ReadLine()) != "End") (Тогава нещата от ред 20 до ред 24 са излишни.)
  19.             {
  20.                 currentFlightNumber = Console.ReadLine();
  21.                 if (currentFlightNumber == "End")
  22.                 {
  23.                     break;
  24.                 }
  25.                 double flightPrice = double.Parse(Console.ReadLine());
  26.                 int currentFlightDuration = int.Parse(Console.ReadLine());
  27.  
  28.                 if (currentFlightDuration < minFlightDuration)
  29.                 {
  30.                     minFlightDuration = currentFlightDuration;
  31.                     //newprice = flightprice;
  32.                     flightNumber = currentFlightNumber;
  33.                     sum = flightPrice * 1.96;
  34.                     hour = currentFlightDuration / 60;
  35.                     min = Math.Abs(hour * 60 - currentFlightDuration); // Може да се сметне и currentFlightDuration % 60
  36.                 }
  37.             }
  38.             Console.WriteLine($"Ticket found for flight {flightNumber} costs {sum:F2} leva with {hour}h {min}m stay");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement