Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace OlympicsAreComing
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- public class OlympicsAreComing
- {
- public static void Main()
- {
- //key - country; value - athletes from this country
- Dictionary<string, List<string>> myDictionary = new Dictionary<string, List<string>>();
- string input = Console.ReadLine();
- while (input != "report")
- {
- string[] inputArguments = input.Split('|');
- string athlete = inputArguments[0];
- string country = inputArguments[1];
- athlete = Regex.Replace(athlete, @"\s{2,}", " ").Trim();
- country = Regex.Replace(country, @"\s{2,}", " ").Trim();
- if (!myDictionary.ContainsKey(country))
- {
- myDictionary.Add(country, new List<string>());
- }
- myDictionary[country].Add(athlete);
- input = Console.ReadLine();
- }
- var orderedData = myDictionary.OrderByDescending(x => x.Value.Count);
- foreach (var kvp in orderedData)
- {
- Console.WriteLine($"{kvp.Key} ({kvp.Value.Distinct().Count()} participants): {kvp.Value.Count} wins");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment