Advertisement
Danny_Berova

04.NSA

Aug 14th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1.  
  2. namespace _04.NSA
  3. {
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.    
  9.     class Program
  10.     {
  11.          public static void Main()
  12.         {
  13.             var spyList = new Dictionary<string, Dictionary<string, long>>();
  14.  
  15.             while (true)
  16.             {
  17.                 var input = Console.ReadLine();
  18.  
  19.                 if (input == "quit")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 var tokens = input
  25.                     .Split(new [] { ' ', '-', '>'}, StringSplitOptions.RemoveEmptyEntries)
  26.                     .ToList();
  27.  
  28.                 if (tokens.Count < 3)
  29.                 {
  30.                     continue;
  31.                 }
  32.  
  33.                 var countryName = tokens[0];
  34.                 var spyName = tokens[1];
  35.                 var spyScore = long.Parse(tokens[tokens.Count - 1]);
  36.  
  37.                 if (!spyList.ContainsKey(countryName))
  38.                 {
  39.                     spyList[countryName] = new Dictionary<string, long>();
  40.                 }
  41.                
  42.                 if (!spyList[countryName].ContainsKey(countryName))
  43.                 {
  44.                     spyList[countryName][spyName] = 0;
  45.                 }
  46.  
  47.                 spyList[countryName][spyName] = spyScore;
  48.             }
  49.  
  50.             foreach (var country in spyList.OrderByDescending(c => c.Value.Keys.Count()))
  51.             {
  52.                 Console.WriteLine($"Country: {country.Key}");
  53.  
  54.                 foreach (var spy in country.Value.OrderByDescending(s => s.Value))
  55.                 {
  56.                     Console.WriteLine($"**{spy.Key} : {spy.Value}");
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement