Advertisement
North_Point

03. Football League

Aug 11th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _03.Football_League
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var pattern = Console.ReadLine();
  15.             var cnt = pattern.Length;
  16.             var dicTopScores = new Dictionary<string, long>();
  17.             var dicTopPoints = new Dictionary<string, long>();
  18.  
  19.             while (true)
  20.             {
  21.                 var input = Console.ReadLine();
  22.                
  23.                 if (input == "final")
  24.                 {
  25.                     break;
  26.                 }
  27.                 var stats = input.Split(' ');
  28.                 var score = stats[stats.Length - 1];
  29.                 var goals = score.Split(':');
  30.                 var first = int.Parse(goals[0]);
  31.                 var last = int.Parse(goals[1]);
  32.  
  33.  
  34.                 var result = Regex.Matches(input, $@"[{pattern}]{{{cnt}}}([A-Za-z])*[{pattern}]{{{cnt}}}");
  35.  
  36.                 StringBuilder words = new StringBuilder();
  37.                 foreach (Group item in result)
  38.                 {
  39.                     var to = item.ToString();
  40.                     var toStr = new string(to.ToCharArray().ToArray());
  41.                     for (int i = toStr.Length - cnt - 1; i > cnt - 1; i--)
  42.                     {
  43.                         words.Append(toStr[i]);
  44.                     }
  45.                     words.Append(" ");
  46.                 }
  47.                 var teams = words.ToString().Split(' ');
  48.                 var firstTeam = teams[0].ToUpper();
  49.                 var secondTeam = teams[1].ToUpper();
  50.  
  51.                 if (!dicTopPoints.ContainsKey(firstTeam))
  52.                 {
  53.                     dicTopPoints[firstTeam] = 0;
  54.                 }
  55.                 if (!dicTopPoints.ContainsKey(secondTeam))
  56.                 {
  57.                     dicTopPoints[secondTeam] = 0;
  58.                 }
  59.  
  60.                 if (first < last)
  61.                 {
  62.                     dicTopPoints[secondTeam] += 3;
  63.                 }
  64.                 else if (first > last)
  65.                 {
  66.                     dicTopPoints[firstTeam] += 3;
  67.                 }
  68.                 else if (first == last)
  69.                 {
  70.                     dicTopPoints[firstTeam] += 1;
  71.                     dicTopPoints[secondTeam] += 1;
  72.                 }
  73.  
  74.                 if (!dicTopScores.ContainsKey(firstTeam))
  75.                 {
  76.                     dicTopScores[firstTeam] = 0;
  77.                 }
  78.                     dicTopScores[firstTeam] += first;
  79.                
  80.                 if (!dicTopScores.ContainsKey(secondTeam))
  81.                 {
  82.                     dicTopScores[secondTeam] = 0;
  83.                 }
  84.                    dicTopScores[secondTeam] += last;
  85.                
  86.             }
  87.             var c = 1;
  88.             Console.WriteLine("League standings:");
  89.             foreach (var item in dicTopPoints.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  90.             {
  91.                 Console.WriteLine("{2}. {0} {1}",item.Key,item.Value,c);
  92.                 c++;
  93.             }
  94.             Console.WriteLine("Top 3 scored goals:");
  95.             foreach (var item in dicTopScores.OrderByDescending(x => x.Value).ThenBy(x => x.Key).Take(3))
  96.             {
  97.                 Console.WriteLine("- {0} -> {1}",item.Key,item.Value);
  98.             }
  99.        }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement