Advertisement
jordan3900

Untitled

Aug 15th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 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.FootballStanding
  9. {
  10. class footballStanding
  11. {
  12. static void Main(string[] args)
  13. {
  14. string key = Console.ReadLine();
  15. string line = Console.ReadLine();
  16. Dictionary<string, long> legueStanding = new Dictionary<string, long>();
  17. Dictionary<string, long> topScores = new Dictionary<string, long>();
  18. string escapedKey = Regex.Escape(key);
  19. string pattern = string.Format(@"{0}(?<teamA>[A-Za-z]+){0}.*{0}(?<teamB>[A-Za-z]+){0}.*(?<teamAScore>\d+):(?<teamBscore>\d+)", escapedKey);
  20.  
  21.  
  22.  
  23.  
  24.  
  25. while (line != "final")
  26. {
  27. Regex regex = new Regex(pattern);
  28. var matches = regex.Matches(line);
  29.  
  30. foreach (Match match in matches)
  31. {
  32.  
  33. string teamA = ReverseStringMethod(match.Groups["teamA"].Value.ToString(), key);
  34. string teamB = ReverseStringMethod(match.Groups["teamB"].Value.ToString(), key);
  35. long scoreA = long.Parse(match.Groups["teamAScore"].Value);
  36. long scoreB = long.Parse(match.Groups["teamBscore"].Value);
  37.  
  38. if (scoreA>scoreB)
  39. {
  40. if (!legueStanding.ContainsKey(teamA))
  41. {
  42. legueStanding[teamA] = 0;
  43. }
  44. if (!legueStanding.ContainsKey(teamB))
  45. {
  46. legueStanding[teamB] = 0;
  47. }
  48. legueStanding[teamA] += 3;
  49. legueStanding[teamB] += 0;
  50. }
  51. else if (scoreB>scoreA)
  52. {
  53. if (!legueStanding.ContainsKey(teamB))
  54. {
  55. legueStanding[teamB] = 0;
  56. }
  57. if (!legueStanding.ContainsKey(teamA))
  58. {
  59. legueStanding[teamA] = 0;
  60. }
  61. legueStanding[teamB] += 3;
  62. legueStanding[teamA] += 0;
  63. }
  64. else
  65. {
  66. if (!legueStanding.ContainsKey(teamB))
  67. {
  68. legueStanding[teamB] = 0;
  69. }
  70. legueStanding[teamB] += 1;
  71. if (!legueStanding.ContainsKey(teamA))
  72. {
  73. legueStanding[teamA] = 0;
  74. }
  75. legueStanding[teamA] += 1;
  76. }
  77. if (!topScores.ContainsKey(teamA) || !topScores.ContainsKey(teamB))
  78. {
  79. if (!topScores.ContainsKey(teamA))
  80. {
  81. topScores[teamA] = 0;
  82. }
  83. if (!topScores.ContainsKey(teamB))
  84. {
  85. topScores[teamB] = 0;
  86. }
  87.  
  88. }
  89. topScores[teamB] += scoreB;
  90. topScores[teamA] += scoreA;
  91. }
  92.  
  93.  
  94. line = Console.ReadLine();
  95. }
  96. int counter = 0;
  97. Console.WriteLine("League standings:");
  98. foreach (var item in legueStanding.OrderByDescending(a=>a.Value))
  99. {
  100. counter++;
  101.  
  102. Console.WriteLine($"{counter}. {item.Key} {item.Value}");
  103.  
  104. }
  105. Console.WriteLine("Top 3 scored goals:");
  106. foreach (var item in topScores.OrderByDescending(a=>a.Value).Take(3))
  107. {
  108. Console.WriteLine($"- {item.Key} -> {item.Value}");
  109. }
  110. }
  111.  
  112. private static string ReverseStringMethod(string item,string key)
  113. {
  114. char[] arr = item.ToUpper().ToCharArray();
  115. Array.Reverse(arr);
  116. return new string(arr);
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement