Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class FootballLeague
- {
- static void Main(string[] args)
- {
- var key = Console.ReadLine();
- List<NationalTeam> leagues = new List<NationalTeam>();
- while (true)
- {
- var input = Console.ReadLine();
- if (input == "final")
- {
- break;
- }
- var inputSplited = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- string teamPattern = $@"{key}([a-zA-Z]+){key}";
- Regex teamRegex = new Regex(teamPattern);
- string firstTeam = teamRegex.Match(inputSplited[0]).Groups[1].Value;
- firstTeam = firstTeam.Reverse().ToString();
- string secondTeam = teamRegex.Match(inputSplited[1]).Groups[1].Value;
- secondTeam = secondTeam.Reverse().ToString();
- int teamOneScore = inputSplited[2].Split(":").Select(int.Parse).First();
- int teamTwoScore = inputSplited[2].Split(":").Select(int.Parse).Last();
- if (teamOneScore>teamTwoScore)
- {
- AddingTeamToList(leagues, firstTeam, teamOneScore, 3);
- AddingTeamToList(leagues, secondTeam, teamTwoScore, 0);
- }
- else if (teamTwoScore>teamOneScore)
- {
- AddingTeamToList(leagues, secondTeam, teamTwoScore, 3);
- AddingTeamToList(leagues, firstTeam, teamOneScore, 0);
- }
- else
- {
- AddingTeamToList(leagues, secondTeam, teamTwoScore, 1);
- AddingTeamToList(leagues, firstTeam, teamOneScore, 1);
- }
- }
- }
- private static void AddingTeamToList(List<NationalTeam> leagues, string firstTeam, int teamOneScore, int v)
- {
- if (leagues.Any(x => x.CountryName == firstTeam))
- {
- var thisCoutry = leagues.FirstOrDefault(x => x.CountryName == firstTeam);
- thisCoutry.TeamPoints += v;
- thisCoutry.GoalsScored += teamOneScore;
- }
- else
- {
- NationalTeam thisTeam = new NationalTeam();
- thisTeam.CountryName = firstTeam;
- thisTeam.GoalsScored = teamOneScore;
- thisTeam.TeamPoints = v;
- leagues.Add(thisTeam);
- }
- }
- }
- class NationalTeam
- {
- public string CountryName { get; set; }
- public int GoalsScored { get; set; }
- public int TeamPoints { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement