Advertisement
tsekotsolov

RainAir

Dec 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace P04_RainAir
  8. {
  9.     class P04_RainAir
  10.     {
  11.         class Customer
  12.         {
  13.             public List<long> Flights { get; set; }
  14.  
  15.         }
  16.  
  17.         static void Main()
  18.         {
  19.             var input = Console.ReadLine();
  20.  
  21.             var customersFlights = new Dictionary<string, Customer>();
  22.  
  23.  
  24.             while (input != "I believe I can fly!")
  25.             {
  26.                 var inputLine = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  27.  
  28.                 if (inputLine[1] != "=")
  29.                 {
  30.                     var customerName = inputLine[0];
  31.  
  32.                     var listOfFlights = new List<long>();
  33.  
  34.                     for (int i = 1; i < inputLine.Count; i++)
  35.                     {
  36.                         listOfFlights.Add(long.Parse(inputLine[i]));
  37.                     }
  38.  
  39.                     Customer customer = new Customer();
  40.  
  41.                     customer.Flights = listOfFlights;
  42.  
  43.                     if (!customersFlights.ContainsKey(customerName))
  44.                     {
  45.                         customersFlights.Add(customerName, customer);
  46.                     }
  47.  
  48.                     else
  49.                     {
  50.                         customersFlights[customerName].Flights.AddRange(listOfFlights);
  51.                     }
  52.                 }
  53.  
  54.                 else
  55.                 {
  56.                     var firstCustomer = inputLine[0];
  57.                     var secondCustomer = inputLine[2];
  58.  
  59.  
  60.                     var ListofSecondCustomerFlights = new List<long>();
  61.  
  62.                     foreach (var item in customersFlights[secondCustomer].Flights)
  63.                     {
  64.                         ListofSecondCustomerFlights.Add(item);
  65.                     }
  66.  
  67.  
  68.                     customersFlights[firstCustomer].Flights.Clear();
  69.  
  70.                     customersFlights[firstCustomer].Flights = ListofSecondCustomerFlights;
  71.  
  72.  
  73.                 }
  74.  
  75.                 input = Console.ReadLine();
  76.             }
  77.  
  78.             foreach (var customer in customersFlights.OrderByDescending(x => x.Value.Flights.Count).ThenBy(x => x.Key))
  79.             {
  80.                 Console.Write($"#{customer.Key} ::: ");
  81.  
  82.  
  83.                 Console.WriteLine(string.Join(", ", customer.Value.Flights.OrderBy(x => x)));
  84.  
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement