using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
var data = "Manchester United 1 Chelsea 0, Arsenal 1 Fulham 1, Swansea 3 Burnley 1, Liverpool 2 Everton 1, Hull 2 Spurs 4, Crystal Palace 1 Manchester City 5, Stoke City 0 Southampton 0, Aston Villa 2 Newcastle 3, West Brom 1 QPR 2, West Ham 1 Leicester 1, Wigan 1 Chelsea 0, Arsenal 1 Manchester United 1, Blackburn 3 Fulham 1, Liverpool 2 Manchester United 1, Swansea 2 Chelsea 4";
var scores = new Scores(data);
Console.WriteLine(scores.GetAllResults());
var teamName = Console.ReadLine();
Console.WriteLine(scores.GetTeamResults(teamName));
public List<FootballMatch> Matches;
Matches = new List<FootballMatch>();
public Scores(string input)
var parsedScores = Parse(input);
this.Matches = parsedScores;
public string GetTeamResults(string teamName, bool isDebug = false)
var matches = this.Matches.Where(m => m.Teams.Item1.Equals(teamName) || m.Teams.Item2.Equals(teamName));
return "No results found.";
matches = matches.Select(m => m.Teams.Item1.Equals(teamName) ? m : m.FlippedMatch());
foreach (var match in matches)
Console.WriteLine("{0} - {1}", match.TeamA, match.TeamB);
int numberOfMatches = matches.Count();
int numberOfWins = matches.Aggregate(0, (result, next) => result + (next.TeamA.Item2 > next.TeamB.Item2 ? 1 : 0));
int numberOfLosses = matches.Aggregate(0, (result, next) => result + (next.TeamA.Item2 < next.TeamB.Item2 ? 1 : 0));
int numberOfDraws = matches.Aggregate(0, (result, next) => result + (next.TeamA.Item2 == next.TeamB.Item2 ? 1 : 0));
int numberOfGoalsScored = matches.Aggregate(0, (result, next) => result + next.TeamA.Item2);
int numberOfGoalsConceded = matches.Aggregate(0, (result, next) => result + next.TeamB.Item2);
int points = numberOfWins*3 + numberOfDraws;
outputString += "Number of matches = " + numberOfMatches + "\n";
outputString += "Number of wins = " + numberOfWins + "\n";
outputString += "Number of draws = " + numberOfDraws + "\n";
outputString += "Number of defeats = " + numberOfLosses + "\n";
outputString += "Goals scored = " + numberOfGoalsScored + "\n";
outputString += "Goals conceded = " + numberOfGoalsConceded + "\n";
outputString += "Number of points = " + points;
public string GetAllResults()
foreach (var match in this.Matches)
results += String.Format("{0} - {1}\n", match.TeamA, match.TeamB);
public static List<FootballMatch> Parse (string input)
Regex footballMatchRegex = new Regex(@",[ ]*", RegexOptions.IgnoreCase);
string[] matchStrings = footballMatchRegex.Split(input);
var matches = new List<FootballMatch>();
foreach (string match in matchStrings)
matches.Add(new FootballMatch(match));
public class FootballMatch
public Tuple<string, string> Teams { get; set; }
public Tuple<int, int> Goals { get; set; }
public Tuple<string, int> TeamA
return new Tuple<string, int>(Teams.Item1, Goals.Item1);
public Tuple<string, int> TeamB
return new Tuple<string, int>(Teams.Item2, Goals.Item2);
this.Teams = new Tuple<string, string>("", "");
this.Goals = new Tuple<int, int>(0, 0);
public FootballMatch(string input)
var parsedMatch = Parse(input);
this.Teams = parsedMatch.Teams;
this.Goals = parsedMatch.Goals;
public FootballMatch FlippedMatch()
var match = new FootballMatch();
match.Teams = new Tuple<string, string>(this.Teams.Item2, this.Teams.Item1);
match.Goals = new Tuple<int, int>(this.Goals.Item2, this.Goals.Item1);
public static FootballMatch Parse(string input)
Regex teamGoalRegex = new Regex(@" (?=\d)|(?<=\d) ", RegexOptions.IgnoreCase);
var matchParts = teamGoalRegex.Split(input);
return new FootballMatch()
Teams = new Tuple<string, string>(matchParts[0], matchParts[2]),
Goals = new Tuple<int, int>(Int32.Parse(matchParts[1]), Int32.Parse(matchParts[3]))