Advertisement
LyubomirRadev

Untitled

Jul 6th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 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.Text.RegularExpressions;
  7.  
  8. namespace _03.Football_League
  9. {
  10.  
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var key = Console.ReadLine();
  16. key = Regex.Escape(key);
  17. var regex = $@"{key}(?<teamOne>.*?){key}.+?{key}(?<teamTwo>.*?){key}.+?(?<teamOneGoals>\d+):(?<teamTwoGoals>\d+)";
  18. var inputInfo = Console.ReadLine();
  19. var teamsTable = new Dictionary<string, int>();
  20. var goalScorers = new Dictionary<string, int>();
  21.  
  22. while (inputInfo != "final")
  23. {
  24. MatchCollection matchInfo = Regex.Matches(inputInfo, regex);
  25.  
  26. foreach (Match match in matchInfo)
  27. {
  28. var teamOne = new string(match.Groups["teamOne"].Value.Reverse().ToArray()).ToUpper();
  29. var teamTwo = new string(match.Groups["teamTwo"].Value.Reverse().ToArray()).ToUpper();
  30. var teamOneGoals = int.Parse(match.Groups["teamOneGoals"].Value);
  31. var teamTwoGoals = int.Parse(match.Groups["teamTwoGoals"].Value);
  32.  
  33. var teamOnePoints = 0;
  34. var teamTwoPoints = 0;
  35. if (teamOneGoals > teamTwoGoals)
  36. {
  37. teamOnePoints = 3;
  38. teamTwoPoints = 0;
  39. }
  40. else if (teamOneGoals < teamTwoGoals)
  41. {
  42. teamOnePoints = 0;
  43. teamTwoPoints = 3;
  44. }
  45. else
  46. {
  47. teamOnePoints = 1;
  48. teamTwoPoints = 1;
  49. }
  50.  
  51. if (!teamsTable.ContainsKey(teamOne))
  52. {
  53. teamsTable[teamOne] = 0;
  54.  
  55. }
  56.  
  57. if (!teamsTable.ContainsKey(teamTwo))
  58. {
  59. teamsTable[teamTwo] = 0;
  60. }
  61.  
  62. teamsTable[teamOne] += teamOnePoints;
  63. teamsTable[teamTwo] += teamTwoPoints;
  64.  
  65.  
  66. if (!goalScorers.ContainsKey(teamOne))
  67. {
  68. goalScorers[teamOne] = 0;
  69.  
  70. }
  71. if (!goalScorers.ContainsKey(teamTwo))
  72. {
  73. goalScorers[teamTwo] = 0;
  74. }
  75.  
  76. goalScorers[teamOne] += teamOneGoals;
  77. goalScorers[teamTwo] += teamTwoGoals;
  78.  
  79. }
  80.  
  81. inputInfo = Console.ReadLine();
  82. }
  83. var postion = 1;
  84. Console.WriteLine("League standings:");
  85. foreach (var team in teamsTable.OrderByDescending(t => t.Value).ThenBy(t => t.Key))
  86. {
  87.  
  88. var teamName = team.Key;
  89. var teamPoints = team.Value;
  90.  
  91. Console.WriteLine($"{postion++}. {teamName} {teamPoints}");
  92.  
  93. }
  94.  
  95. Console.WriteLine("Top 3 scored goals:");
  96. foreach(var goals in goalScorers.OrderByDescending(g => g.Value).ThenBy(g => g.Key).Take(3))
  97. {
  98. var teamName = goals.Key;
  99. var teamGoals = goals.Value;
  100.  
  101. Console.WriteLine($"- {teamName} -> {teamGoals}");
  102. }
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement