Advertisement
Mike_Goodman92

Untitled

Oct 29th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 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 Problem_3.Football_Standings
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14.  
  15. Dictionary<string, int> teamPlayScores = new Dictionary<string, int>();
  16. Dictionary<string, int> teamGoalCount = new Dictionary<string, int>();
  17.  
  18. string key = Console.ReadLine();
  19.  
  20. string[] forbidentChars = new string[] { "?", ".", "+", "$", "^", "*", "(", ")", "\\", "/", "|" };
  21.  
  22. foreach (var forbidChar in forbidentChars)
  23. {
  24. if (key.Contains(forbidChar))
  25. {
  26. key = key.Replace(forbidChar, $"\\{forbidChar}");
  27. break;
  28. }
  29. }
  30.  
  31.  
  32.  
  33. string lineFormation = Console.ReadLine();
  34.  
  35. Regex findTeamPatter = new Regex($"({key})([a-zA-Z]+)+({key})");
  36. Regex findScorePatter = new Regex(@"(([0-9]+):([0-9]+))");
  37.  
  38. while (lineFormation != "final")
  39. {
  40. MatchCollection getBothTeams = findTeamPatter.Matches(lineFormation);
  41.  
  42. string leftTeam = getBothTeams[0].ToString();
  43. string rightTeam = getBothTeams[1].ToString();
  44.  
  45. foreach (var forbidChar in forbidentChars)
  46. {
  47. if (key.Contains($"\\{forbidChar}"))
  48. {
  49. key = key.Replace($"\\{forbidChar}", forbidChar);
  50. break;
  51. }
  52. }
  53.  
  54. leftTeam = leftTeam.Replace(key, "");
  55. leftTeam = Reverse(leftTeam).ToUpper();
  56.  
  57. if (!teamPlayScores.Keys.Contains(leftTeam))
  58. {
  59. teamPlayScores[leftTeam] = 0;
  60. teamGoalCount[leftTeam] = 0;
  61. }
  62.  
  63. rightTeam = rightTeam.Replace(key, "");
  64. rightTeam = Reverse(rightTeam).ToUpper();
  65.  
  66. if (!teamPlayScores.Keys.Contains(rightTeam))
  67. {
  68. teamPlayScores[rightTeam] = 0;
  69. teamGoalCount[rightTeam] = 0;
  70. }
  71.  
  72. MatchCollection getScores = findScorePatter.Matches(lineFormation);
  73. string[] score = getScores[0].ToString().Split(':');
  74.  
  75. string leftTeamScore = score[0];
  76. string rightTeamScore = score[1];
  77.  
  78. teamGoalCount[leftTeam] += int.Parse(leftTeamScore);
  79. teamGoalCount[rightTeam] += int.Parse(rightTeamScore);
  80.  
  81. string condition = "";
  82.  
  83. if (int.Parse(leftTeamScore) > int.Parse(rightTeamScore))
  84. {
  85. condition = "1";
  86. }
  87. if (int.Parse(leftTeamScore) < int.Parse(rightTeamScore))
  88. {
  89. condition = "2";
  90. }
  91. if (int.Parse(leftTeamScore) == int.Parse(rightTeamScore))
  92. {
  93. condition = "x";
  94. }
  95.  
  96. switch (condition)
  97. {
  98. case "1": teamPlayScores[leftTeam] += 3; break;
  99. case "2": teamPlayScores[rightTeam] += 3; break;
  100. case "x":
  101. teamPlayScores[leftTeam] += 1;
  102. teamPlayScores[rightTeam] += 1;
  103. break;
  104. }
  105.  
  106. lineFormation = Console.ReadLine();
  107.  
  108. foreach (var forbidChar in forbidentChars)
  109. {
  110. if (key.Contains(forbidChar))
  111. {
  112. key = key.Replace(forbidChar, $"\\{forbidChar}");
  113. break;
  114. }
  115. }
  116. }
  117.  
  118. //Output
  119. Console.WriteLine("League standings:");
  120.  
  121. int countPlaces = 1;
  122. foreach (var team in teamPlayScores.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  123. {
  124. Console.WriteLine($"{countPlaces}. {team.Key} {team.Value}");
  125. countPlaces++;
  126. }
  127. Console.WriteLine($"Top 3 scored goals:");
  128. foreach (var team in teamGoalCount.OrderByDescending(x => x.Value).Take(3))
  129. {
  130. Console.WriteLine($"- {team.Key} -> {team.Value}");
  131. }
  132.  
  133. }
  134.  
  135. public static string Reverse(string s)
  136. {
  137. char[] charArray = s.ToCharArray();
  138. Array.Reverse(charArray);
  139. return new string(charArray);
  140. }
  141.  
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement