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.Threading.Tasks;
- class FootballLeague
- {
- static void Main()
- {
- string key = Console.ReadLine();
- var standings = new Dictionary<string, long>();
- var scorers = new Dictionary<string, long>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "final")
- {
- break;
- }
- var firstStartIndex = input.IndexOf(key) + key.Length;
- var firstEndIndex = input.IndexOf(key, firstStartIndex);
- var firstTeamNameLength = firstEndIndex - firstStartIndex;
- var team1 = input.Substring(firstStartIndex, firstTeamNameLength);
- team1 = Reverse(team1);
- team1 = team1.ToUpper();
- var secondStartIndex = input.IndexOf(key, firstEndIndex + key.Length) + key.Length;
- var secondEndIndex = input.IndexOf(key, secondStartIndex);
- var secondTeamNameLength = secondEndIndex - secondStartIndex;
- var team2 = input.Substring(secondStartIndex, secondTeamNameLength);
- team2 = Reverse(team2);
- team2 = team2.ToUpper();
- string[] splitedInput = input.Split(' ').ToArray();
- string score = splitedInput[2];
- long[] scoreTokens = score.Split(':').Select(long.Parse).ToArray();
- long score1 = scoreTokens[0];
- long score2 = scoreTokens[1];
- long pointsTeam1 = 0;
- long pointsTeam2 = 0;
- if (score1 > score2)
- {
- pointsTeam1 = 3;
- }
- else if (score1 == score2)
- {
- pointsTeam1 = 1;
- pointsTeam2 = 1;
- }
- else
- {
- pointsTeam2 = 3;
- }
- if (standings.ContainsKey(team1))
- {
- standings[team1] += pointsTeam1;
- scorers[team1] += score1;
- }
- else
- {
- standings[team1] = pointsTeam1;
- scorers[team1] = score1;
- }
- if (standings.ContainsKey(team2))
- {
- standings[team2] += pointsTeam2;
- scorers[team2] += score2;
- }
- else
- {
- standings[team2] = pointsTeam2;
- scorers[team2] = score2;
- }
- }
- standings = standings.OrderBy(x => x.Key).OrderByDescending(x => x.Value).ToDictionary(t => t.Key, t => t.Value);
- scorers = scorers.OrderBy(x => x.Key).OrderByDescending(x => x.Value).Take(3).ToDictionary(t => t.Key, t => t.Value);
- long place = 1;
- Console.WriteLine("League standings:");
- foreach (var team in standings.Keys)
- {
- Console.WriteLine($"{place}. {team} {standings[team]}");
- place++;
- }
- Console.WriteLine("Top 3 scored goals:");
- foreach (var team in scorers.Keys)
- {
- Console.WriteLine($"- {team} -> {scorers[team]}");
- }
- }
- 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