Advertisement
sivancheva

FootBallStandings2

Sep 15th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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 _03_FootballStandings2
  9. {
  10. class FootballStandings2
  11. {
  12. static void Main(string[] args)
  13. {
  14. var key = Regex.Escape(Console.ReadLine());
  15.  
  16. var patern = $@"^.*(?:{key})(?<team1>[a-zA-Z]*)(?:{key}).* .*(?:{key})(?<team2>[a-zA-Z]*)(?:{key}).* (?<goalsTeam1>\d+):(?<goalsTeam2>\d+).*$";
  17.  
  18. var matchRegex = new Regex(patern);
  19. var chart = new Dictionary<string, Score>();
  20.  
  21. while (true)
  22. {
  23. var line = Console.ReadLine();
  24. if (line == "final")
  25. {
  26. break;
  27. }
  28.  
  29. var match = matchRegex.Match(line); // tuk matchvame celija teks ot inputa, a ne samo otdelnite elementi , kakto bi bilo s Matches
  30. var team1Name = new string(match.Groups["team1"].Value.ToUpper().Reverse().ToArray());
  31. var team2Name = new string(match.Groups["team2"].Value.ToUpper().Reverse().ToArray());
  32. var team1Goals = int.Parse(match.Groups["goalsTeam1"].Value);
  33. var team2Goals = int.Parse(match.Groups["goalsTeam2"].Value);
  34.  
  35. if (!chart.ContainsKey(team1Name))
  36. {
  37. chart.Add(team1Name, new Score());
  38.  
  39. }
  40.  
  41. if (!chart.ContainsKey(team2Name))
  42. {
  43. chart.Add(team2Name, new Score());
  44.  
  45. }
  46.  
  47. chart[team1Name].Goals += team1Goals;
  48. chart[team2Name].Goals += team2Goals;
  49.  
  50. if (team1Goals > team2Goals)
  51. {
  52. chart[team1Name].Points += 3;
  53.  
  54. }
  55.  
  56. else if (team1Goals < team2Goals)
  57. {
  58. chart[team2Name].Points += 3;
  59. }
  60. else
  61. {
  62. chart[team1Name].Points += 1;
  63. chart[team2Name].Points += 1;
  64. }
  65.  
  66.  
  67. }
  68. var leagueStandings = chart
  69. .OrderByDescending(a => a.Value.Points)
  70. .ThenBy(a => a.Key);
  71.  
  72. Console.WriteLine("League standings:");
  73.  
  74. }
  75. class Score
  76. {
  77. public decimal Points { get; set; }
  78. public decimal Goals { get; set; }
  79. }
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement