Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Linq;
- class MainClass
- {
- public static void Main()
- {
- string key = Console.ReadLine();
- string input = Console.ReadLine();
- var standings = new Dictionary<string, int>(); //for the points gained
- var goals = new Dictionary<string, int>(); //for the number of goals scored
- while (!input.ToLower().Equals("final"))
- {
- var args = input.Split(new[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries);
- string encryptedTeamA = args[0];
- string encryptedTeamB = args[1];
- int teamAGoals = int.Parse(args[2]);
- int teamBGoals = int.Parse(args[3]);
- var teamANameChars = encryptedTeamA.Skip(encryptedTeamA.IndexOf(key) + key.Length).ToArray();
- encryptedTeamA = string.Join("", teamANameChars);
- string teamAName = string.Join("", teamANameChars.Take(encryptedTeamA.IndexOf(key)).Reverse()).ToUpper();
- var teamBNameChars = encryptedTeamB.Skip(encryptedTeamB.IndexOf(key) + key.Length).ToArray();
- encryptedTeamB = string.Join("", teamBNameChars);
- string teamBName = string.Join("", teamBNameChars.Take(encryptedTeamB.IndexOf(key)).Reverse()).ToUpper();
- InsertInStandings(standings, teamAName, teamBName, teamAGoals, teamBGoals);
- InsertInGoals(goals, teamAName, teamBName, teamAGoals, teamBGoals);
- input = Console.ReadLine();
- }
- PrintStandings(standings);
- PrintBest3Teams(goals);
- }
- static void PrintStandings(Dictionary<string, int> standings)
- {
- Console.WriteLine("League standings:");
- int counter = 1;
- foreach (var team in standings.OrderByDescending(t => t.Value).ThenBy(t => t.Key))
- {
- Console.WriteLine($"{counter}. {team.Key} {team.Value}");
- counter++;
- }
- }
- static void PrintBest3Teams(Dictionary<string, int> goals)
- {
- Console.WriteLine("Top 3 scored goals:");
- foreach (var team in goals.OrderByDescending(t => t.Value).ThenBy(t => t.Key).Take(3))
- {
- Console.WriteLine($"- {team.Key} -> {team.Value}");
- }
- }
- static void InsertInStandings(Dictionary<string, int> standings, string teamAName, string teamBName, int teamAGoals, int teamBGoals)
- {
- if (!standings.ContainsKey(teamAName))
- standings.Add(teamAName, 0);
- if (!standings.ContainsKey(teamBName))
- standings.Add(teamBName, 0);
- int teamAPoints = 1;
- int teamBPoints = 1;
- if (teamBGoals != teamAGoals)
- {
- teamAPoints = (teamAGoals > teamBGoals) ? 3 : 0;
- teamBPoints = (teamBGoals > teamAGoals) ? 3 : 0;
- }
- standings[teamAName] += teamAPoints;
- standings[teamBName] += teamBPoints;
- }
- static void InsertInGoals(Dictionary<string, int> goals, string teamAName, string teamBName, int teamAGoals, int teamBGoals)
- {
- if (!goals.ContainsKey(teamAName))
- goals.Add(teamAName, 0);
- if (!goals.ContainsKey(teamBName))
- goals.Add(teamBName, 0);
- goals[teamAName] += teamAGoals;
- goals[teamBName] += teamBGoals;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment