Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. class FootballLeague
  7. {
  8. static void Main(string[] args)
  9. {
  10. var key = Console.ReadLine();
  11.  
  12. List<NationalTeam> leagues = new List<NationalTeam>();
  13. while (true)
  14. {
  15. var input = Console.ReadLine();
  16. if (input == "final")
  17. {
  18. break;
  19. }
  20. var inputSplited = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  21. string teamPattern = $@"{key}([a-zA-Z]+){key}";
  22. Regex teamRegex = new Regex(teamPattern);
  23.  
  24. string firstTeam = teamRegex.Match(inputSplited[0]).Groups[1].Value;
  25. firstTeam = firstTeam.Reverse().ToString();
  26. string secondTeam = teamRegex.Match(inputSplited[1]).Groups[1].Value;
  27. secondTeam = secondTeam.Reverse().ToString();
  28.  
  29. int teamOneScore = inputSplited[2].Split(":").Select(int.Parse).First();
  30. int teamTwoScore = inputSplited[2].Split(":").Select(int.Parse).Last();
  31.  
  32. if (teamOneScore>teamTwoScore)
  33. {
  34. AddingTeamToList(leagues, firstTeam, teamOneScore, 3);
  35. AddingTeamToList(leagues, secondTeam, teamTwoScore, 0);
  36. }
  37. else if (teamTwoScore>teamOneScore)
  38. {
  39. AddingTeamToList(leagues, secondTeam, teamTwoScore, 3);
  40. AddingTeamToList(leagues, firstTeam, teamOneScore, 0);
  41. }
  42. else
  43. {
  44. AddingTeamToList(leagues, secondTeam, teamTwoScore, 1);
  45. AddingTeamToList(leagues, firstTeam, teamOneScore, 1);
  46. }
  47.  
  48.  
  49.  
  50.  
  51. }
  52. }
  53.  
  54. private static void AddingTeamToList(List<NationalTeam> leagues, string firstTeam, int teamOneScore, int v)
  55. {
  56. if (leagues.Any(x => x.CountryName == firstTeam))
  57. {
  58. var thisCoutry = leagues.FirstOrDefault(x => x.CountryName == firstTeam);
  59. thisCoutry.TeamPoints += v;
  60. thisCoutry.GoalsScored += teamOneScore;
  61. }
  62. else
  63. {
  64. NationalTeam thisTeam = new NationalTeam();
  65. thisTeam.CountryName = firstTeam;
  66. thisTeam.GoalsScored = teamOneScore;
  67. thisTeam.TeamPoints = v;
  68. leagues.Add(thisTeam);
  69. }
  70. }
  71. }
  72. class NationalTeam
  73. {
  74. public string CountryName { get; set; }
  75. public int GoalsScored { get; set; }
  76. public int TeamPoints { get; set; }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement