Advertisement
Guest User

problem4

a guest
Jun 1st, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Problem4
  10. {
  11. class Problem4
  12. {
  13. private static Dictionary<String, Country> _dict;
  14. static void Main(string[] args)
  15. {
  16. _dict = new System.Collections.Generic.Dictionary<string, Country>();
  17. while (true)
  18. {
  19.  
  20. String input = Console.ReadLine().Trim();
  21. if (input == "report")
  22. {
  23. break;
  24. }
  25.  
  26. input = Regex.Replace(input, @"([\s]{2,})", " ");
  27.  
  28. String[] arr = input.Split('|');
  29. String countryName = arr[1].Trim();
  30. String playerName = arr[0].Trim();
  31. // Console.WriteLine(arr[0]);
  32. // Console.WriteLine(arr[1]);
  33. if (_dict.ContainsKey(countryName))
  34. {
  35. _dict[countryName].AddPlayer(playerName);
  36. }
  37. else
  38. {
  39. _dict.Add(countryName, new Country(countryName));
  40. _dict[countryName].AddPlayer(playerName);
  41. }
  42. }
  43.  
  44. var ord = from pair in _dict
  45. orderby pair.Value.GetWins() descending
  46. select pair;
  47.  
  48. foreach (var o in ord)
  49. {
  50. Console.WriteLine("{0} ({1} participants): {2} wins", o.Key, o.Value.GetNumberOfPlayers(), o.Value.GetWins());
  51. }
  52. }
  53.  
  54. public class Country
  55. {
  56. private String _name;
  57. private HashSet<String> _players;
  58. private int _wins;
  59.  
  60. public Country(String name)
  61. {
  62. _players = new System.Collections.Generic.HashSet<string>();
  63. SetName(name);
  64. _wins = 0;
  65. }
  66.  
  67. public void SetName(String name)
  68. {
  69. this._name = name;
  70. }
  71.  
  72. public String GetName()
  73. {
  74. return this._name;
  75. }
  76.  
  77. public void AddPlayer(String name)
  78. {
  79. if (_players.Contains(name))
  80. {
  81. this._wins++;
  82. }
  83. else
  84. {
  85. _players.Add(name);
  86. this._wins++;
  87. }
  88. }
  89.  
  90. public int GetWins()
  91. {
  92. return this._wins;
  93. }
  94.  
  95. public int GetNumberOfPlayers()
  96. {
  97. return this._players.Count();
  98. }
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement