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 Problem3
- {
- static void Main()
- {
- string key = Console.ReadLine();
- Dictionary<string, int> teamPoints = new Dictionary<string, int>();
- Dictionary<string, int> teamGoals = new Dictionary<string, int>();
- while (true)
- {
- string info = Console.ReadLine();
- if (info == "final")
- {
- break;
- }
- string[] teamScore = info.Split();
- string teamA = teamScore[0];
- string teamB = teamScore[1];
- var score = teamScore[2].Split(':');
- int teamAGoals = int.Parse(score[0]);
- int teamBGoals = int.Parse(score[1]);
- string teamAname = SubstracTeamName(teamA, key);
- string teamBname = SubstracTeamName(teamB, key);
- if (teamGoals.ContainsKey(teamAname))
- {
- teamGoals[teamAname] += teamAGoals;
- }
- else
- {
- teamGoals.Add(teamAname, teamAGoals);
- }
- if (teamGoals.ContainsKey(teamBname))
- {
- teamGoals[teamBname] += teamBGoals;
- }
- else
- {
- teamGoals.Add(teamBname, teamBGoals);
- }
- // POINTS FOR THE TEAMS
- if (teamAGoals > teamBGoals)
- {
- if (teamPoints.ContainsKey(teamAname))
- {
- int count;
- teamPoints.TryGetValue(teamAname, out count);
- teamPoints[teamAname] = count + 3;
- //teamPoints[teamAname] + 3;
- }
- else
- {
- teamPoints.Add(teamAname, 3);
- }
- if (teamPoints.ContainsKey(teamBname))
- {
- int count;
- teamPoints.TryGetValue(teamBname, out count);
- teamPoints[teamBname] = count + 0;
- //teamPoints[teamBname] + 0;
- }
- else
- {
- teamPoints.Add(teamBname, 0);
- }
- }
- else if (teamAGoals < teamBGoals)
- {
- if (teamPoints.ContainsKey(teamBname))
- {
- int count;
- teamPoints.TryGetValue(teamBname, out count);
- teamPoints[teamBname] = count + 3;
- //teamPoints[teamBname] + 3;
- }
- else
- {
- teamPoints.Add(teamBname, 3);
- }
- if(teamPoints.ContainsKey(teamAname))
- {
- int count;
- teamPoints.TryGetValue(teamAname, out count);
- teamPoints[teamAname] = count + 0;
- //teamPoints[teamAname] + 0;
- }
- else
- {
- teamPoints.Add(teamAname, 0);
- }
- }
- else
- {
- if (teamPoints.ContainsKey(teamAname))
- {
- int count;
- teamPoints.TryGetValue(teamAname, out count);
- teamPoints[teamAname] = count + 1;
- //teamPoints[teamAname] + 1;
- }
- else
- {
- teamPoints.Add(teamAname, 1);
- }
- if (teamPoints.ContainsKey(teamBname))
- {
- int count;
- teamPoints.TryGetValue(teamBname, out count);
- teamPoints[teamBname] = count + 1;
- //teamPoints[teamBname] + 1;
- }
- else
- {
- teamPoints.Add(teamBname, 1);
- }
- }
- //Points for the teams ++++++++++++++++++++++++++++
- }
- Console.WriteLine("League standings:");
- var orderedByPoints = teamPoints.OrderByDescending(team => team.Value).ThenBy(team => team.Key);
- int counter = 1;
- foreach (var team in orderedByPoints)
- {
- Console.WriteLine("{0}. {1} {2}", counter, team.Key, team.Value);
- counter++;
- }
- Console.WriteLine("Top 3 scored goals:");
- var orderedByGoals = teamGoals.OrderByDescending(team => team.Value).ThenBy(team => team.Key).Take(3);
- foreach (var team in orderedByGoals)
- {
- Console.WriteLine("- {0} -> {1}", team.Key, team.Value);
- }
- }
- public static string SubstracTeamName(string team, string key)
- {
- int indexOfKey = team.IndexOf(key);
- string secondPart = team.Substring(indexOfKey + key.Length);
- int secondKey = secondPart.IndexOf(key);
- var teamName = team.Substring(indexOfKey + key.Length, secondKey).ToUpper();
- char[] arr = teamName.ToCharArray();
- Array.Reverse(arr);
- return new string (arr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement