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;
- using System.Text.RegularExpressions;
- namespace _03.FootballStanding
- {
- class footballStanding
- {
- static void Main(string[] args)
- {
- string key = Console.ReadLine();
- string line = Console.ReadLine();
- Dictionary<string, long> legueStanding = new Dictionary<string, long>();
- Dictionary<string, long> topScores = new Dictionary<string, long>();
- string escapedKey = Regex.Escape(key);
- string pattern = string.Format(@"{0}(?<teamA>[A-Za-z]+){0}.*{0}(?<teamB>[A-Za-z]+){0}.*(?<teamAScore>\d+):(?<teamBscore>\d+)", escapedKey);
- while (line != "final")
- {
- Regex regex = new Regex(pattern);
- var matches = regex.Matches(line);
- foreach (Match match in matches)
- {
- string teamA = ReverseStringMethod(match.Groups["teamA"].Value.ToString(), key);
- string teamB = ReverseStringMethod(match.Groups["teamB"].Value.ToString(), key);
- long scoreA = long.Parse(match.Groups["teamAScore"].Value);
- long scoreB = long.Parse(match.Groups["teamBscore"].Value);
- if (scoreA>scoreB)
- {
- if (!legueStanding.ContainsKey(teamA))
- {
- legueStanding[teamA] = 0;
- }
- if (!legueStanding.ContainsKey(teamB))
- {
- legueStanding[teamB] = 0;
- }
- legueStanding[teamA] += 3;
- legueStanding[teamB] += 0;
- }
- else if (scoreB>scoreA)
- {
- if (!legueStanding.ContainsKey(teamB))
- {
- legueStanding[teamB] = 0;
- }
- if (!legueStanding.ContainsKey(teamA))
- {
- legueStanding[teamA] = 0;
- }
- legueStanding[teamB] += 3;
- legueStanding[teamA] += 0;
- }
- else
- {
- if (!legueStanding.ContainsKey(teamB))
- {
- legueStanding[teamB] = 0;
- }
- legueStanding[teamB] += 1;
- if (!legueStanding.ContainsKey(teamA))
- {
- legueStanding[teamA] = 0;
- }
- legueStanding[teamA] += 1;
- }
- if (!topScores.ContainsKey(teamA) || !topScores.ContainsKey(teamB))
- {
- if (!topScores.ContainsKey(teamA))
- {
- topScores[teamA] = 0;
- }
- if (!topScores.ContainsKey(teamB))
- {
- topScores[teamB] = 0;
- }
- }
- topScores[teamB] += scoreB;
- topScores[teamA] += scoreA;
- }
- line = Console.ReadLine();
- }
- int counter = 0;
- Console.WriteLine("League standings:");
- foreach (var item in legueStanding.OrderByDescending(a=>a.Value))
- {
- counter++;
- Console.WriteLine($"{counter}. {item.Key} {item.Value}");
- }
- Console.WriteLine("Top 3 scored goals:");
- foreach (var item in topScores.OrderByDescending(a=>a.Value).Take(3))
- {
- Console.WriteLine($"- {item.Key} -> {item.Value}");
- }
- }
- private static string ReverseStringMethod(string item,string key)
- {
- char[] arr = item.ToUpper().ToCharArray();
- Array.Reverse(arr);
- return new string(arr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement