Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class P04OlympicsAreComing
  5. {
  6.     static void Main()
  7.     {
  8.         Dictionary<string, SortedDictionary<string, int>> output = new Dictionary<string, SortedDictionary<string, int>>();
  9.         string inputLine = Console.ReadLine();
  10.  
  11.         while (!inputLine.ToLower().Equals("report"))
  12.         {
  13.             string[] currLine = inputLine.Trim().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  14.             string[] currName = currLine[0].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  15.             string playerName = String.Empty;
  16.             if (currName.Length > 1)
  17.             {
  18.                 playerName = currName[0].Trim() + " " + currName[1].Trim();
  19.             }
  20.             else
  21.             {
  22.                 playerName = currName[0].Trim();
  23.             }
  24.  
  25.             string[] currCountry = currLine[1].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  26.             string countryName = String.Empty;
  27.             if (currCountry.Length > 1)
  28.             {
  29.                 countryName = currCountry[0].Trim() + " " + currCountry[1].Trim();
  30.             }
  31.             else
  32.             {
  33.                 countryName = currCountry[0].Trim();
  34.             }
  35.  
  36.             if (!output.ContainsKey(countryName))
  37.             {
  38.                 output[countryName] = new SortedDictionary<string, int>();
  39.             }
  40.  
  41.             if (!output[countryName].ContainsKey(playerName))
  42.             {
  43.                 output[countryName][playerName] = 1;
  44.             }
  45.             else
  46.             {
  47.                 output[countryName][playerName] += 1;
  48.             }
  49.             inputLine = Console.ReadLine();
  50.         }
  51.  
  52.         var items =
  53.             from item in output orderby item.Value.Sum(x => x.Value) descending select item;
  54.        
  55.         foreach (var item in items)
  56.         {
  57.             int wins = 0;
  58.             Console.Write(string.Format(item.Key + " (" + item.Value.Count + " participants): "));
  59.             foreach (var win in item.Value)
  60.             {
  61.                 wins += win.Value;
  62.             }
  63.             Console.WriteLine(wins + " wins");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement