Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace OlympicsAreComing
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, HashSet<string>> countries = new Dictionary<string, HashSet<string>>();
- List<string> countriesOccurences = new List<string>();
- while (true)
- {
- string line = Console.ReadLine();
- if (line.Equals("report"))
- {
- break;
- }
- string[] tokens = line.Split('|');
- string athlete = tokens[0];
- athlete = Regex.Replace(athlete, @"\s+", " ").Trim();
- string country = tokens[1];
- country = Regex.Replace(country, @"\s+", " ").Trim();
- countriesOccurences.Add(country);
- if (!countries.ContainsKey(country))
- {
- countries.Add(country, new HashSet<string>());
- countries[country].Add(athlete);
- }
- else
- {
- countries[country].Add(athlete);
- }
- }
- Dictionary<string, int[]> resultDictionary = new Dictionary<string, int[]>();
- foreach (var country in countries)
- {
- int wins = 0;
- List<string> winsList = countriesOccurences;
- for (int i = 0; i < winsList.Count; i++)
- {
- if (winsList[i].Equals(country.Key))
- {
- wins++;
- }
- }
- int[] nums =
- {
- wins,
- country.Value.Count
- };
- resultDictionary.Add(country.Key, nums);
- }
- foreach (var country in resultDictionary.OrderByDescending(key => key.Value[0]))
- {
- Console.WriteLine("{0} ({1} participants): {2} wins", country.Key, country.Value[1], country.Value[0]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement