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;
- using System.Threading.Tasks;
- namespace Problem_3.Football_Standings
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> teamPlayScores = new Dictionary<string, int>();
- Dictionary<string, int> teamGoalCount = new Dictionary<string, int>();
- string key = Console.ReadLine();
- string[] forbidentChars = new string[] { "?", ".", "+", "$", "^", "*", "(", ")", "\\", "/", "|" };
- foreach (var forbidChar in forbidentChars)
- {
- if (key.Contains(forbidChar))
- {
- key = key.Replace(forbidChar, $"\\{forbidChar}");
- break;
- }
- }
- string lineFormation = Console.ReadLine();
- Regex findTeamPatter = new Regex($"({key})([a-zA-Z]+)+({key})");
- Regex findScorePatter = new Regex(@"(([0-9]+):([0-9]+))");
- while (lineFormation != "final")
- {
- MatchCollection getBothTeams = findTeamPatter.Matches(lineFormation);
- string leftTeam = getBothTeams[0].ToString();
- string rightTeam = getBothTeams[1].ToString();
- foreach (var forbidChar in forbidentChars)
- {
- if (key.Contains($"\\{forbidChar}"))
- {
- key = key.Replace($"\\{forbidChar}", forbidChar);
- break;
- }
- }
- leftTeam = leftTeam.Replace(key, "");
- leftTeam = Reverse(leftTeam).ToUpper();
- if (!teamPlayScores.Keys.Contains(leftTeam))
- {
- teamPlayScores[leftTeam] = 0;
- teamGoalCount[leftTeam] = 0;
- }
- rightTeam = rightTeam.Replace(key, "");
- rightTeam = Reverse(rightTeam).ToUpper();
- if (!teamPlayScores.Keys.Contains(rightTeam))
- {
- teamPlayScores[rightTeam] = 0;
- teamGoalCount[rightTeam] = 0;
- }
- MatchCollection getScores = findScorePatter.Matches(lineFormation);
- string[] score = getScores[0].ToString().Split(':');
- string leftTeamScore = score[0];
- string rightTeamScore = score[1];
- teamGoalCount[leftTeam] += int.Parse(leftTeamScore);
- teamGoalCount[rightTeam] += int.Parse(rightTeamScore);
- string condition = "";
- if (int.Parse(leftTeamScore) > int.Parse(rightTeamScore))
- {
- condition = "1";
- }
- if (int.Parse(leftTeamScore) < int.Parse(rightTeamScore))
- {
- condition = "2";
- }
- if (int.Parse(leftTeamScore) == int.Parse(rightTeamScore))
- {
- condition = "x";
- }
- switch (condition)
- {
- case "1": teamPlayScores[leftTeam] += 3; break;
- case "2": teamPlayScores[rightTeam] += 3; break;
- case "x":
- teamPlayScores[leftTeam] += 1;
- teamPlayScores[rightTeam] += 1;
- break;
- }
- lineFormation = Console.ReadLine();
- foreach (var forbidChar in forbidentChars)
- {
- if (key.Contains(forbidChar))
- {
- key = key.Replace(forbidChar, $"\\{forbidChar}");
- break;
- }
- }
- }
- //Output
- Console.WriteLine("League standings:");
- int countPlaces = 1;
- foreach (var team in teamPlayScores.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{countPlaces}. {team.Key} {team.Value}");
- countPlaces++;
- }
- Console.WriteLine($"Top 3 scored goals:");
- foreach (var team in teamGoalCount.OrderByDescending(x => x.Value).Take(3))
- {
- Console.WriteLine($"- {team.Key} -> {team.Value}");
- }
- }
- public static string Reverse(string s)
- {
- char[] charArray = s.ToCharArray();
- Array.Reverse(charArray);
- return new string(charArray);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement