Advertisement
YavorGrancharov

RainAir

Jan 4th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace RainAir
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             Dictionary<string, List<int>> data = new Dictionary<string, List<int>>();
  14.  
  15.             while (input != "I believe I can fly!")
  16.             {
  17.                 if (!input.Contains("="))
  18.                 {
  19.                     string[] tokens = input.Split(new [] { ' ' }, 2);
  20.                     string customerName = tokens[0];
  21.                     string flights = tokens[1];
  22.                     List<int> customerFlights = flights.Split(' ').Select(int.Parse).ToList();
  23.  
  24.                     if (!data.ContainsKey(customerName))
  25.                     {
  26.                         data.Add(customerName, new List<int>());
  27.                     }
  28.                     data[customerName].AddRange(customerFlights);
  29.                 }
  30.                 else
  31.                 {
  32.                     string[] tokens = input.Split(new string[] {" = "},StringSplitOptions.RemoveEmptyEntries);
  33.                     string customerName = tokens[0];
  34.                     string secondname = tokens[1];
  35.  
  36.                     if (!data.ContainsKey(customerName))
  37.                     {
  38.                         data.Add(customerName, new List<int>());
  39.                     }
  40.                     if (data.ContainsKey(customerName) && data.ContainsKey(secondname))
  41.                     {
  42.                         data[customerName] = new List<int>(data[secondname]);
  43.                     }
  44.                 }
  45.                 input = Console.ReadLine();
  46.             }
  47.             foreach (var entry in data
  48.                      .OrderByDescending(x => x.Value.Count())
  49.                      .ThenBy(x => x.Key))
  50.             {
  51.                 Console.WriteLine("#{0} ::: {1}", entry.Key, string.Join(", ", entry.Value.OrderBy(x => x)));
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement