Aliendreamer

wormsparty

Aug 18th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 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 wormsworldpartyizpit30april
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Dictionary<string, Dictionary<string,long>> wormsParty = new Dictionary<string, Dictionary<string, long>>();
  15.             bool exist = false;
  16.             string input = Console.ReadLine();
  17.             List<string> names = new List<string>();
  18.  
  19.             while (input != "quit")
  20.             {
  21.  
  22.                 string[] inputTokens = input.Split(new string[] {" -> "}, StringSplitOptions.RemoveEmptyEntries).ToArray();
  23.  
  24.                 string name = inputTokens[0];
  25.                 string team = inputTokens[1];
  26.                long score = long.Parse(inputTokens[2]);
  27.  
  28.                 if (names.Contains(name))
  29.                 {
  30.                         exist = true;
  31.                 }
  32.                
  33.  
  34.                 if (!exist)
  35.                 {
  36.                     if (!wormsParty.ContainsKey(team))
  37.                     {
  38.                         wormsParty.Add(team, new Dictionary<string, long>());
  39.                     }
  40.                     wormsParty[team].Add(name, score);
  41.                     names.Add(name);
  42.                 }
  43.  
  44.  
  45.  
  46.                 input = Console.ReadLine();
  47.  
  48.             }
  49.             // logic done output left!
  50.  
  51.            wormsParty= wormsParty.OrderByDescending(x => x.Value.Sum(y => y.Value))
  52.             .ThenByDescending(x => x.Value.Sum(y => y.Value) / x.Value.Count())
  53.             .ToDictionary(x => x.Key, x => x.Value);
  54.  
  55.  
  56.             int count = 1;
  57.             foreach (KeyValuePair<string,Dictionary<string,long>> pair in wormsParty)
  58.             {
  59.                
  60.                 string team = pair.Key;
  61.                 Dictionary<string, long> worms = pair.Value;
  62.                 long total = worms.Values.Sum();
  63.                 Console.WriteLine($"{count}. Team: {team} - {total}");
  64.  
  65.                 foreach (KeyValuePair<string,long> kvp in  worms.OrderByDescending(x=>x.Value))
  66.                 {
  67.                     Console.WriteLine($"###{kvp.Key} : {kvp.Value}");
  68.                 }
  69.                 count++;
  70.             }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.         }
  77.     }
  78. }
Add Comment
Please, Sign In to add comment