Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class P04OlympicsAreComing
- {
- static void Main()
- {
- Dictionary<string, SortedDictionary<string, int>> output = new Dictionary<string, SortedDictionary<string, int>>();
- string inputLine = Console.ReadLine();
- while (!inputLine.ToLower().Equals("report"))
- {
- string[] currLine = inputLine.Trim().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string[] currName = currLine[0].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string playerName = String.Empty;
- if (currName.Length > 1)
- {
- playerName = currName[0].Trim() + " " + currName[1].Trim();
- }
- else
- {
- playerName = currName[0].Trim();
- }
- string[] currCountry = currLine[1].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string countryName = String.Empty;
- if (currCountry.Length > 1)
- {
- countryName = currCountry[0].Trim() + " " + currCountry[1].Trim();
- }
- else
- {
- countryName = currCountry[0].Trim();
- }
- if (!output.ContainsKey(countryName))
- {
- output[countryName] = new SortedDictionary<string, int>();
- }
- if (!output[countryName].ContainsKey(playerName))
- {
- output[countryName][playerName] = 1;
- }
- else
- {
- output[countryName][playerName] += 1;
- }
- inputLine = Console.ReadLine();
- }
- var items =
- from item in output orderby item.Value.Sum(x => x.Value) descending select item;
- foreach (var item in items)
- {
- int wins = 0;
- Console.Write(string.Format(item.Key + " (" + item.Value.Count + " participants): "));
- foreach (var win in item.Value)
- {
- wins += win.Value;
- }
- Console.WriteLine(wins + " wins");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement