public Match(Team homeTeam, Team awayTeam, Score score, int id) { this.homeTeam = homeTeam; this.awayTeam = awayTeam; this.score = score; this.id = id; }
public Match(Team hometeam, Team awayteam, Score score, int id) { this.HomeTeam = hometeam; this.AwayTeam = awayteam; this.Score = score; this.Id = id; }
public static void AddMatch(int id, Team homeTeam, Team awayTeam, Score score) { if (!matchExists(id)) { Matches.Add(new Match(id, homeTeam, awayTeam, score)); } }
private static void AddMatch(int id, string homeTeamName, string awayTeamName, string score) { Team t = new Team(homeTeamName, " ", new DateTime(1850, 1, 1)); t.Name = homeTeamName; Team s = new Team(awayTeamName, " ", new DateTime(1850, 1, 1)); s.Name = awayTeamName; Score sc; string[] scc = score.Split(' '); sc = new Score(int.Parse(scc[0]), int.Parse(scc[1])); Match match = new Match(t, s, sc, id); if (League.CheckIfMatchExist(match)) { throw new InvalidOperationException("This match already exist"); } League.AddMatch(match); Console.WriteLine("Match - Confirmed"); }
private static void AddMatch(string homeTeamName, string awayTeamName, string idStr, string homeTeamGoals, string awayTeamGoals) { if (League.Teams.All(t => t.Name != homeTeamName)) { throw new InvalidOperationException("Team name"); } if (League.Teams.All(t => t.Name != awayTeamName)) { throw new InvalidOperationException("Team name"); } var homeTeam = League.Teams.First(t => t.Name == homeTeamName); var awayTeam = League.Teams.First(t => t.Name == awayTeamName); var id = int.Parse(idStr); var score = new Score(int.Parse(homeTeamGoals), int.Parse(awayTeamGoals)); var match = new Match(homeTeam, awayTeam, id, score); League.AddMatches(match); Console.WriteLine("Match with ID: " + idStr + " has been added succesfully"); }
static void Main(string[] args) { var key = Regex.Escape(Console.ReadLine()); // escape key before using it. var pattern = $@"^.*(?:{key})(?<teamA>[a-zA-Z]*)(?:{key}).* .*(?:{key})(?<teamB>[a-zA-Z]*)(?:{key}).* (?<scoreA>\d+)\:(?<scoreB>\d+).*$"; var teamScore = new Dictionary <string, Score>(); var inputLine = Console.ReadLine(); while (inputLine != "final") { var match = Regex.Match(inputLine, pattern); if (!match.Success) { inputLine = Console.ReadLine(); continue; } var teamA = new string(match.Groups["teamA"].Value.ToUpper().Reverse().ToArray()); var teamB = new string(match.Groups["teamB"].Value.ToUpper().Reverse().ToArray()); var scoreA = int.Parse(match.Groups["scoreA"].Value); var scoreB = int.Parse(match.Groups["scoreB"].Value); if (!teamScore.ContainsKey(teamA)) { teamScore[teamA] = new Score(); } if (!teamScore.ContainsKey(teamB)) { teamScore[teamB] = new Score(); } if (scoreA > scoreB) { teamScore[teamA].Points += 3; } else if (scoreA == scoreB) { teamScore[teamA].Points++; teamScore[teamB].Points++; } else { teamScore[teamB].Points += 3; } teamScore[teamA].Goals += scoreA; teamScore[teamB].Goals += scoreB; inputLine = Console.ReadLine(); } var place = 1; Console.WriteLine("League standings:"); foreach (var team in teamScore.OrderByDescending(x => x.Value.Points).ThenBy(x => x.Key)) { Console.WriteLine("{0}. {1} {2}", place++, team.Key, team.Value.Points); } Console.WriteLine("Top 3 scored goals:"); foreach (var team in teamScore.OrderByDescending(x => x.Value.Goals).ThenBy(x => x.Key).Take(3)) { Console.WriteLine("- {0} -> {1}", team.Key, team.Value.Goals); } }