Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- namespace Loty
- {
- class Program
- {
- static void Main(string[] args)
- {
- new Thread(() =>
- {
- Thread.CurrentThread.IsBackground = true;
- /* run your code here */
- for (; ; )
- {
- if (Console.ReadKey(true).Key == ConsoleKey.Escape) Environment.Exit(0);
- }
- }).Start();
- List<DateTime> odloty = new List<DateTime>();
- List<DateTime> przyloty = new List<DateTime>();
- odloty.Add(DateTime.ParseExact("08.00", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("10.16", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("09.43", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("11.52", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("11.19", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("13.31", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("12.47", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("15.00", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("14.00", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("16.08", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("15.45", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("17.55", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("19.00", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("21.27", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("21.45", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("23.58", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("22.50", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("01.55", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- odloty.Add(DateTime.ParseExact("23.45", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- przyloty.Add(DateTime.ParseExact("02.50", "HH.mm", System.Globalization.CultureInfo.InvariantCulture));
- DateTime g;
- for (; ; ) {
- Console.WriteLine("Wprowadź godzinę z minutami: ");
- try
- {
- g = DateTime.ParseExact(Console.ReadLine(), "HH.mm", System.Globalization.CultureInfo.InvariantCulture);
- if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) break;
- int i = 0;
- int difference = int.MaxValue;
- foreach (DateTime c in odloty)
- {
- if(Math.Abs(g.Subtract(c).TotalMinutes) < difference) // && c > g) //wtedy tylko po tej godzinie
- {
- difference = (int)g.Subtract(c).TotalMinutes;
- i = odloty.IndexOf(c);
- }
- }
- Console.WriteLine("Najbliższy odlot: " + odloty[i].ToString("HH:mm") + " przylot: " + przyloty[i].ToString("HH:mm"));
- Console.ReadLine();
- } catch(Exception e)
- {
- Console.WriteLine("To nie jest poprawna godzina.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement