Advertisement
shady_obeyd

05.Points Counter

Aug 4th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.PointsCounter
  8. {
  9.     class PointsCounter
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> data = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             string input = Console.ReadLine().Replace("@", "").Replace("%", "").Replace("$", "").Replace("*", "");
  16.  
  17.             while (input != "Result")
  18.             {
  19.                 string[] tokens = input.Split('|');
  20.  
  21.                 string teamName = string.Empty;
  22.                 string playerName = string.Empty;
  23.                 int points = int.Parse(tokens[2]);
  24.  
  25.                 for (int i = 0; i < tokens[0].Length; i++)
  26.                 {
  27.                     if (char.IsLower(tokens[0][i]))
  28.                     {
  29.                         teamName = tokens[1];
  30.                         playerName = tokens[0];
  31.                     }
  32.                     else
  33.                     {
  34.                         teamName = tokens[0];
  35.                         playerName = tokens[1];
  36.                     }
  37.                 }
  38.  
  39.                 if (!data.ContainsKey(teamName))
  40.                 {
  41.                     data.Add(teamName, new Dictionary<string, int>());
  42.                 }
  43.  
  44.                 if (!data[teamName].ContainsKey(playerName))
  45.                 {
  46.                     data[teamName].Add(playerName, points);
  47.                 }
  48.                 else
  49.                 {
  50.                     data[teamName][playerName] = points;
  51.                 }
  52.  
  53.                 input = Console.ReadLine().Replace("@", "").Replace("%", "").Replace("$", "").Replace("*", "");
  54.             }
  55.             data =
  56.                 data
  57.                 .OrderByDescending(v => v.Value.Values.Sum())
  58.                 .ToDictionary(k => k.Key, v => v.Value);
  59.  
  60.             foreach (var teamData in data)
  61.             {
  62.                 string teamName = teamData.Key;
  63.  
  64.                 Dictionary<string, int> playerData = teamData.Value;
  65.  
  66.                 var newPlayerData =
  67.                     playerData
  68.                     .OrderByDescending(v => v.Value)
  69.                     .Take(1)
  70.                     .ToDictionary(k => k.Key, v => v.Value);
  71.  
  72.                 Console.WriteLine($"{teamName} => {playerData.Values.Sum()}");
  73.  
  74.                 foreach (var player in newPlayerData)
  75.                 {
  76.                     Console.WriteLine($"Most points scored by {player.Key}");
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement