Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace OlympicsAreComing
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.             List<string> name = new List<string>();
  16.             List<string> country = new List<string>();
  17.  
  18.             var atlets = new Dictionary<string, List<string>>();
  19.  
  20.             while (input != "report")
  21.             {
  22.                 string[] inputArr = input.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);              
  23.                 name.Add(inputArr[0]);
  24.                 country.Add(inputArr[1]);
  25.                 input = Console.ReadLine();
  26.             }
  27.  
  28.             for (int i = 0; i < name.Count; i++)
  29.             {
  30.                 name[i] = name[i].Trim();
  31.                 Regex.Replace(name[i], @"\s+", " ");
  32.                 name[i] = name[i].Replace("\t", "");
  33.                 name[i] = name[i].Replace(" ", "");
  34.             }
  35.  
  36.             for (int i = 0; i < country.Count; i++)
  37.             {
  38.                 country[i] = country[i].Trim();
  39.             }
  40.  
  41.             for (int i = 0; i < country.Count; i++)
  42.             {
  43.                 if (!atlets.ContainsKey(country[i]))
  44.                 {
  45.                     atlets.Add(country[i], new List<string>());
  46.                 }
  47.                 atlets[country[i]].Add(name[i]);
  48.             }
  49.  
  50.             var orderedAtlets = atlets.OrderByDescending(x => x.Value.Count());
  51.  
  52.             StringBuilder result = new StringBuilder();
  53.  
  54.             foreach (var item in orderedAtlets)
  55.             {
  56.                 result.AppendFormat("{0} ({1} participants): {2} wins", item.Key, item.Value.Distinct().Count(), item.Value.Count()).AppendLine();
  57.             }
  58.  
  59.             Console.Write(result.ToString());
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement