-Annie-

OlympicsAreComing

Jun 10th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. namespace OlympicsAreComing
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class OlympicsAreComing
  9.     {
  10.         public static void Main()
  11.         {
  12.             //key - country;    value - athletes from this country
  13.             Dictionary<string, List<string>> myDictionary = new Dictionary<string, List<string>>();
  14.             string input = Console.ReadLine();
  15.  
  16.             while (input != "report")
  17.             {
  18.                 string[] inputArguments = input.Split('|');
  19.                 string athlete = inputArguments[0];
  20.                 string country = inputArguments[1];
  21.  
  22.                 athlete = Regex.Replace(athlete, @"\s{2,}", " ").Trim();
  23.                 country = Regex.Replace(country, @"\s{2,}", " ").Trim();
  24.  
  25.                 if (!myDictionary.ContainsKey(country))
  26.                 {
  27.                     myDictionary.Add(country, new List<string>());
  28.                 }
  29.  
  30.                 myDictionary[country].Add(athlete);
  31.  
  32.                 input = Console.ReadLine();
  33.             }
  34.  
  35.             var orderedData = myDictionary.OrderByDescending(x => x.Value.Count);
  36.  
  37.             foreach (var kvp in orderedData)
  38.             {
  39.                 Console.WriteLine($"{kvp.Key} ({kvp.Value.Distinct().Count()} participants): {kvp.Value.Count} wins");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment