Advertisement
reking12

Untitled

Apr 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P03MOBA_Challenger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var playerPosAndSkill = new Dictionary<string, Dictionary<string, double>>();
  12.             var playerAndSkill = new Dictionary<string, double>();
  13.  
  14.             while (true)
  15.             {
  16.                 string end = Console.ReadLine();
  17.                 if (end == "Season end")
  18.                 {
  19.                     break;
  20.                 }
  21.                 if (end.Contains("->"))
  22.                 {
  23.                     List<string> input = end.Split(" -> ").ToList();
  24.                     string player = input[0];
  25.                     string position = input[1];
  26.                     double points = double.Parse(input[2]);
  27.                     if (!playerPosAndSkill.ContainsKey(player))
  28.                     {
  29.                         playerPosAndSkill[player] = new Dictionary<string, double>();
  30.                         playerPosAndSkill[player][position] = points;
  31.                     }
  32.                     else if (playerPosAndSkill[player].ContainsKey(position))
  33.                     {
  34.                         if (playerPosAndSkill[player][position] < points)
  35.                         {
  36.                             playerPosAndSkill[player][position] = points;
  37.                         }
  38.                     }
  39.                     else
  40.                     {
  41.                         playerPosAndSkill[player][position] = points;
  42.                     }
  43.                     if (!playerAndSkill.ContainsKey(player))
  44.                     {
  45.                         playerAndSkill[player] = points;
  46.                     }
  47.                     else
  48.                     {
  49.                         playerAndSkill[player] += points;
  50.                     }
  51.                    
  52.  
  53.                 }
  54.                 else if (end.Contains("vs"))
  55.                 {
  56.                     List<string> input = end.Split(" vs ").ToList();
  57.                     string player1 = input[0];
  58.                     string player2 = input[1];
  59.                     if (playerPosAndSkill.ContainsKey(player1) && playerPosAndSkill.ContainsKey(player2))
  60.                     {
  61.                         foreach (var position1 in playerPosAndSkill[player1])
  62.                         {
  63.                             foreach (var position2 in playerPosAndSkill[player2])
  64.                             {
  65.                                 if (position1.Key == position2.Key)
  66.                                 {
  67.                                     if (position1.Value > position2.Value)
  68.                                     {
  69.                                         playerPosAndSkill.Remove(player2);
  70.                                     }
  71.                                     else if (position1.Value < position2.Value)
  72.                                     {
  73.                                         playerPosAndSkill.Remove(player1);
  74.                                     }
  75.                                 }
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.             int count = 0;
  82.             foreach (var item in playerPosAndSkill.OrderByDescending(x => playerAndSkill[x.Key]))
  83.             {
  84.                 int i = 0;
  85.                 // Console.WriteLine($"{playerAndSkill[item.Key]}: {playerAndSkill[item.Value.ToString()]} skills");
  86.                 // Console.WriteLine(item.Key);
  87.                 foreach (var sdf in playerAndSkill.OrderByDescending(x => x.Value).ThenBy(x=> x.Key))
  88.                 {
  89.                     if (count == i)
  90.                     {
  91.                         Console.WriteLine($"{sdf.Key}: {sdf.Value} skill");
  92.                     }
  93.                     i++;
  94.                 }
  95.                 foreach (var sdf in item.Value.OrderByDescending(x => x.Value).ThenBy(x=> x.Key))
  96.                 {
  97.                     Console.WriteLine($"- {sdf.Key} <::> {sdf.Value}");
  98.                 }
  99.                 count++;
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement