Advertisement
YavorGrancharov

Worms_World_Party

Aug 18th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Worms_World_Party
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             Dictionary<string, Dictionary<string, long>> data =
  14.                 new Dictionary<string, Dictionary<string, long>>();
  15.  
  16.             while (input != "quit")
  17.             {
  18.                 string[] tokens = input
  19.                     .Split(new string[] { " -> " },
  20.                     StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.                 string wormName = tokens[0];
  23.                 string teamName = tokens[1];
  24.                 long wormScore = long.Parse(tokens[2]);
  25.  
  26.                 try
  27.                 {
  28.                     var hasWorm = data.Values.Where(x => x.ContainsKey(wormName)).First().Count;
  29.                 }
  30.                 catch (Exception e)
  31.                 {
  32.                     if (!data.ContainsKey(teamName))
  33.                     {
  34.                         data.Add(teamName, new Dictionary<string, long>());
  35.                     }
  36.  
  37.                     if (!data[teamName].ContainsKey(wormName))
  38.                     {
  39.                         data[teamName][wormName] = 0;
  40.                     }
  41.                     data[teamName][wormName] = wormScore;
  42.                 }
  43.                 input = Console.ReadLine();
  44.             }
  45.  
  46.             int indexer = 1;
  47.             foreach (var team in data
  48.                 .OrderByDescending(x => x.Value.Values.Sum())
  49.                 .ThenByDescending(x => x.Value.Values.Sum() / x.Value.Values.Count))
  50.             {
  51.                 Console.WriteLine($"{indexer}. Team: {team.Key} - {team.Value.Values.Sum()}");
  52.  
  53.                 Dictionary<string, long> wormScores = team.Value;
  54.  
  55.                 foreach (var worm in wormScores.OrderByDescending(x => x.Value))
  56.                 {
  57.                     Console.WriteLine($"###{worm.Key} : {worm.Value}");
  58.                 }
  59.                 indexer++;
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement