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;
- namespace _3.FootballStandigs
- {
- class Program
- {
- static void Main(string[] args)
- {
- var goalTeam = new Dictionary<string, long>();
- var pointTeam = new Dictionary<string, long>();
- string pattern = Console.ReadLine();
- while(true)
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- if(input[0]=="final")
- {
- break;
- }
- string teamFirst = TeamNameFinder(input[0].ToString(),pattern);
- string teamSecond= TeamNameFinder(input[1].ToString(), pattern);
- string[] goals = input[2].Split(':').ToArray();
- long firstTeamGoals = long.Parse(goals[0]);
- long secondTeamGoals = long.Parse(goals[1]);
- long firsTeamPoints = 0;
- long secondTeamPoints = 0;
- if(firstTeamGoals==secondTeamGoals)
- {
- firsTeamPoints++;
- secondTeamPoints++;
- }
- else if(firstTeamGoals>secondTeamGoals)
- {
- firsTeamPoints += 3;
- }
- else
- {
- secondTeamPoints += 3;
- }
- AddingPointsToKeyValuePairs(teamFirst, firsTeamPoints, firstTeamGoals,goalTeam,pointTeam);
- AddingPointsToKeyValuePairs(teamSecond, secondTeamPoints, secondTeamGoals,goalTeam,pointTeam);
- }
- if(pointTeam.Count>0)
- {
- Console.WriteLine("League standings:");
- int counter = 1;
- foreach (var item in pointTeam.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{counter}. {item.Key} {item.Value}");
- counter++;
- }
- }
- if(goalTeam.Count>0)
- {
- Console.WriteLine("Top 3 scored goals:");
- int count = 0;
- foreach (var item in goalTeam.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"- {item.Key} -> {item.Value}");
- count++;
- if (count == 3)
- {
- break;
- }
- }
- }
- }
- static void AddingPointsToKeyValuePairs(string team, long teamPoints, long teamGoals, Dictionary<string, long> goalTeam, Dictionary<string, long> pointTeam)
- {
- if(!goalTeam.ContainsKey(team))
- {
- goalTeam.Add(team, teamGoals);
- }
- else if(goalTeam.ContainsKey(team))
- {
- goalTeam[team] += teamGoals;
- }
- if(!pointTeam.ContainsKey(team))
- {
- pointTeam.Add(team, teamPoints);
- }
- else if(pointTeam.ContainsKey(team))
- {
- pointTeam[team] += teamPoints;
- }
- }
- static string TeamNameFinder(string text, string pattern)
- {
- var unreversed = new StringBuilder();
- int start = text.IndexOf(pattern, 0) + pattern.Length;
- int end = text.IndexOf(pattern, start);
- string name = "";
- for (int i = start; i < end; i++)
- {
- unreversed.Append(text[i]);
- }
- for (int i = unreversed.Length - 1; i >= 0; i--)
- {
- name += unreversed[i];
- }
- name = name.ToUpper();
- return name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement