Advertisement
zh_stoqnov

OlympicsAreComing

Jun 2nd, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 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. Dictionary<string, HashSet<string>> countries = new Dictionary<string, HashSet<string>>();
  15. List<string> countriesOccurences = new List<string>();
  16. while (true)
  17. {
  18. string line = Console.ReadLine();
  19. if (line.Equals("report"))
  20. {
  21. break;
  22. }
  23.  
  24. string[] tokens = line.Split('|');
  25. string athlete = tokens[0];
  26. athlete = Regex.Replace(athlete, @"\s+", " ").Trim();
  27. string country = tokens[1];
  28. country = Regex.Replace(country, @"\s+", " ").Trim();
  29. countriesOccurences.Add(country);
  30. if (!countries.ContainsKey(country))
  31. {
  32. countries.Add(country, new HashSet<string>());
  33. countries[country].Add(athlete);
  34. }
  35. else
  36. {
  37. countries[country].Add(athlete);
  38. }
  39. }
  40.  
  41. Dictionary<string, int[]> resultDictionary = new Dictionary<string, int[]>();
  42. foreach (var country in countries)
  43. {
  44. int wins = 0;
  45. List<string> winsList = countriesOccurences;
  46.  
  47. for (int i = 0; i < winsList.Count; i++)
  48. {
  49. if (winsList[i].Equals(country.Key))
  50. {
  51. wins++;
  52. }
  53. }
  54. int[] nums =
  55. {
  56. wins,
  57. country.Value.Count
  58. };
  59. resultDictionary.Add(country.Key, nums);
  60. }
  61.  
  62. foreach (var country in resultDictionary.OrderByDescending(key => key.Value[0]))
  63. {
  64. Console.WriteLine("{0} ({1} participants): {2} wins", country.Key, country.Value[1], country.Value[0]);
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement