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;
- using System.Text.RegularExpressions;
- namespace FootballLeague
- {
- public class FootballLeague
- {
- public static void Main()
- {
- string decryptionKey = Console.ReadLine();
- string pattern = Regex.Escape(decryptionKey) + "(.*?)" + Regex.Escape(decryptionKey);
- Regex footballTeam = new Regex(pattern);
- Dictionary<string, long> leagueStandings = new Dictionary<string, long>();
- Dictionary<string, long> topScoredGoalds = new Dictionary<string, long>();
- string inputLine = Console.ReadLine();
- while (inputLine != "final")
- {
- string[] matchInfo = inputLine.Split();
- string firstTeamName = ReverseTeamName(footballTeam
- .Match(matchInfo[0])
- .Groups[1]
- .ToString()
- .ToUpper());
- string secondTeamName = ReverseTeamName(footballTeam
- .Match(matchInfo[1])
- .Groups[1]
- .ToString()
- .ToUpper());
- string[] scoredGoalsInfo = matchInfo[matchInfo.Length - 1].Split(':');
- long firstTeamGoals = long.Parse(scoredGoalsInfo[0]);
- long secondTeamGoals = long.Parse(scoredGoalsInfo[1]);
- int firstTeamPoints = 0;
- int secondTeamPoints = 0;
- if (firstTeamGoals == secondTeamGoals)
- {
- firstTeamPoints = 1;
- secondTeamPoints = 1;
- }
- else
- {
- firstTeamPoints = firstTeamGoals > secondTeamGoals ? 3 : 0;
- secondTeamPoints = firstTeamGoals < secondTeamGoals ? 3 : 0;
- }
- //filling the teams points and goals
- if (!leagueStandings.ContainsKey(firstTeamName) &&
- !topScoredGoalds.ContainsKey(firstTeamName))
- {
- leagueStandings.Add(firstTeamName, 0);
- topScoredGoalds.Add(firstTeamName, 0);
- }
- leagueStandings[firstTeamName] += firstTeamPoints;
- topScoredGoalds[firstTeamName] += firstTeamGoals;
- if (!leagueStandings.ContainsKey(secondTeamName) &&
- !topScoredGoalds.ContainsKey(secondTeamName))
- {
- leagueStandings.Add(secondTeamName, 0);
- topScoredGoalds.Add(secondTeamName, 0);
- }
- leagueStandings[secondTeamName] += secondTeamPoints;
- topScoredGoalds[secondTeamName] += secondTeamGoals;
- inputLine = Console.ReadLine();
- }
- Console.WriteLine("League standings:");
- int placeInStandings = 1;
- foreach (KeyValuePair<string, long> pair in leagueStandings
- .OrderByDescending(p => p.Value)
- .ThenBy(n => n.Key))
- {
- Console.WriteLine($"{placeInStandings}. {pair.Key} {pair.Value}");
- placeInStandings++;
- }
- Dictionary<string, long> topThreeScoredGoals = topScoredGoalds
- .OrderByDescending(g => g.Value)
- .ThenBy(n => n.Key)
- .Take(3)
- .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
- Console.WriteLine("Top 3 scored goals:");
- foreach (KeyValuePair<string, long> pair in topThreeScoredGoals)
- {
- Console.WriteLine($"- {pair.Key} -> {pair.Value}");
- }
- }
- public static string ReverseTeamName(string teamName)
- {
- StringBuilder toReturn = new StringBuilder();
- for (int currLetter = 0; currLetter < teamName.Length; currLetter++)
- {
- toReturn.Append(teamName[teamName.Length - 1 - currLetter]);
- }
- return toReturn.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement