Guest User

04.WormsWorldParty

a guest
Jul 29th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 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 _04.WormsWorldParty
  8. {
  9.     class WormsWorldParty
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, Dictionary<string, long>> teams = new Dictionary<string, Dictionary<string, long>>();
  14.             string input = Console.ReadLine();
  15.  
  16.             while (input != "quit")
  17.             {
  18.                 string[] tokens = input.Split(new string[] { " -> " }, StringSplitOptions.None).Select(x => x.Trim()).ToArray();
  19.  
  20.                 string playerName = tokens[0];
  21.                 string teamName = tokens[1];
  22.                 long score = long.Parse(tokens[2]);
  23.  
  24.                 bool containsPlayer = false;
  25.  
  26.                 foreach (var item in teams)
  27.                 {
  28.                     if (item.Value.ContainsKey(playerName))
  29.                     {
  30.                         containsPlayer = true;
  31.                     }
  32.                 }
  33.  
  34.                 if (!containsPlayer)
  35.                 {
  36.                     if (!teams.ContainsKey(teamName))
  37.                     {
  38.                         teams.Add(teamName, new Dictionary<string, long>());
  39.                     }
  40.                     teams[teamName][playerName] = score;
  41.                 }
  42.                
  43.  
  44.                 input = Console.ReadLine();
  45.             }
  46.             teams =
  47.                 teams
  48.                 .OrderByDescending(t => t.Value.Values.Sum())
  49.                 .ThenByDescending(t => t.Value.Values.Average())
  50.                 .ToDictionary(k => k.Key, v => v.Value);
  51.  
  52.             int cntr = 1;
  53.             foreach (var teamData in teams)
  54.             {
  55.                 string teamName = teamData.Key;
  56.                 Dictionary<string, long> players = teamData.Value;
  57.  
  58.                 players =
  59.                     players
  60.                     .OrderByDescending(s => s.Value)
  61.                     .ToDictionary(k => k.Key, v => v.Value);
  62.  
  63.                 Console.WriteLine($"{cntr}. Team: {teamName} - {players.Values.Sum()}");
  64.  
  65.                 foreach (var playerData in players)
  66.                 {
  67.                     string player = playerData.Key;
  68.                     long score = playerData.Value;
  69.  
  70.                     Console.WriteLine($"###{player} : {score}");
  71.                 }
  72.                 cntr++;
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment