Advertisement
YavorGrancharov

NSA

Aug 19th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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 NSA
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             Dictionary<string, Dictionary<string, int>> data =
  16.                 new Dictionary<string, Dictionary<string, int>>();
  17.  
  18.             while (input != "quit")
  19.             {
  20.                 string[] parts = input
  21.                     .Split(new string[] { " -> " },
  22.                     StringSplitOptions.RemoveEmptyEntries);
  23.  
  24.                 string countryName = parts[0];
  25.                 string spyName = parts[1];
  26.                 int daysInService = int.Parse(parts[2]);
  27.  
  28.                 if (!data.ContainsKey(countryName))
  29.                 {
  30.                     data[countryName] = new Dictionary<string, int>();
  31.                 }
  32.  
  33.                 if (!data[countryName].ContainsKey(spyName))
  34.                 {
  35.                     data[countryName][spyName] = 0;
  36.                 }
  37.                 data[countryName][spyName] = daysInService;
  38.  
  39.                 input = Console.ReadLine();
  40.             }
  41.            
  42.             foreach (var country in data.OrderByDescending(x => x.Value.Values.Count))
  43.             {
  44.                 Console.WriteLine($"Country: {country.Key}");
  45.  
  46.                 Dictionary<string, int> spyes = country.Value;
  47.  
  48.                 foreach (var spy in spyes.OrderByDescending(x => x.Value))
  49.                 {
  50.                     Console.WriteLine($"**{spy.Key} : {spy.Value}");
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement