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;
- namespace Football_League
- {
- class Program
- {
- static void Main(string[] args)
- {
- string key = Console.ReadLine();
- key = Regex.Escape(key);
- string pattern = $@"{key}(?<teamOne>.*?){key}.+?{key}(?<teamTwo>.*?){key}.+?(?<teamOneGoals>\d+):(?<teamTwoGoals>\d+)";
- string input = Console.ReadLine();
- Dictionary<string, int> standings = new Dictionary<string, int>();
- Dictionary<string, int> goals = new Dictionary<string, int>();
- while (input != "final")
- {
- MatchCollection teams = Regex.Matches(input, pattern);
- foreach (Match team in teams)
- {
- string teamOne = new string(team.Groups["teamOne"].Value.Reverse().ToArray()).ToUpper();
- string teamTwo = new string(team.Groups["teamTwo"].Value.Reverse().ToArray()).ToUpper();
- var teamOneGoals = int.Parse(team.Groups["teamOneGoals"].Value);
- var teamTwoGoals = int.Parse(team.Groups["teamTwoGoals"].Value);
- var teamOnePoints = 0;
- var teamTwoPoints = 0;
- if (teamOneGoals > teamTwoGoals)
- {
- teamOnePoints = 3;
- teamTwoPoints = 0;
- }
- else if (teamOneGoals < teamTwoGoals)
- {
- teamOnePoints = 0;
- teamTwoPoints = 3;
- }
- else
- {
- teamOnePoints = 1;
- teamTwoPoints = 1;
- }
- if (!standings.ContainsKey(teamOne))
- {
- standings[teamOne] = 0;
- }
- if (!standings.ContainsKey(teamTwo))
- {
- standings[teamTwo] = 0;
- }
- standings[teamOne] += teamOnePoints;
- standings[teamTwo] += teamTwoPoints;
- if (!goals.ContainsKey(teamOne))
- {
- goals[teamOne] = 0;
- }
- if (!goals.ContainsKey(teamTwo))
- {
- goals[teamTwo] = 0;
- }
- goals[teamOne] += teamOneGoals;
- goals[teamTwo] += teamTwoGoals;
- }
- input = Console.ReadLine();
- }
- var indexer = 1;
- Console.WriteLine("League standings:");
- foreach (var team in standings.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{indexer}. {team.Key} {team.Value}");
- indexer++;
- }
- Console.WriteLine("Top 3 scored goals:");
- foreach (var goal in goals.OrderByDescending(x => x.Value).ThenBy(x => x.Key).Take(3))
- {
- Console.WriteLine($"- {goal.Key} -> {goal.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement