Advertisement
optybg

Untitled

May 10th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 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 WormsWorldParty
  8. {
  9.     public class WormsWorldParty
  10.     {
  11.         public static void Main()
  12.         {
  13.             var input = Console.ReadLine();
  14.  
  15.             Dictionary<string, Dictionary<string, long>> rank = new Dictionary<string, Dictionary<string, long>>();
  16.  
  17.             while (input!= "quit")
  18.             {
  19.                 var inputParams = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToList();
  20.  
  21.                 var wormName = inputParams[0];
  22.                 var teamName = inputParams[1];
  23.                 var wormScore = long.Parse(inputParams[2]);
  24.                                
  25.  
  26.                 if (!rank.ContainsKey(teamName))
  27.                 {
  28.                     rank[teamName] = new Dictionary<string, long>();
  29.                 }
  30.  
  31.  
  32.                 if (PlayerExist(rank, wormName) == true)
  33.                 {
  34.                     input = Console.ReadLine();
  35.                     continue;
  36.                 }
  37.  
  38.                 if (!rank[teamName].ContainsKey(wormName))
  39.                 {                    
  40.                     rank[teamName][wormName] = 0;
  41.                 }
  42.  
  43.                 rank[teamName][wormName] = wormScore;
  44.  
  45.                 input = Console.ReadLine();
  46.             }
  47.  
  48.             var orderedRank = rank.OrderByDescending(x => x.Value.Values.Sum())
  49.                 .ThenByDescending(x => x.Value.Values.Sum() / x.Value.Keys.Count)
  50.                 .ToDictionary(x=> x.Key, x=> x.Value);
  51.  
  52.             var counter = 1;
  53.             foreach (var team in orderedRank)
  54.             {
  55.                 Console.WriteLine(counter+". " +"Team: "+ team.Key + " - " + team.Value.Values.Sum());
  56.                 foreach (var player in team.Value.OrderByDescending(x => x.Value).ToList())
  57.                 {
  58.  
  59.                     Console.WriteLine("###" + player.Key + " : "+ player.Value);
  60.                 }
  61.                 counter++;
  62.             }
  63.  
  64.         }
  65.  
  66.         private static bool PlayerExist(Dictionary<string, Dictionary<string, long>> rank, string wormName)
  67.         {
  68.             bool playerExist = false;
  69.             foreach (var team in rank.Values)
  70.             {
  71.                 playerExist = team.ContainsKey(wormName);
  72.                 if (playerExist == true)
  73.                 {
  74.                     return true;
  75.                 }
  76.                
  77.             }
  78.             return false;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement