Advertisement
Guest User

Untitled

a guest
May 5th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Worms_World_Party
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             Dictionary<string, Dictionary<string, decimal>> TeamWormScore = new Dictionary<string, Dictionary<string, decimal>>();
  12.  
  13.             List<string> wormExistList = new List<string>();
  14.  
  15.             string inputLine = Console.ReadLine();
  16.  
  17.             while (inputLine != "quit")
  18.             {
  19.                 string[] splitInput = inputLine.Split(new string[] { " -> " }, StringSplitOptions.None).ToArray();
  20.  
  21.                 string wormName = splitInput[0];
  22.                 string team = splitInput[1];
  23.                 decimal score = decimal.Parse(splitInput[2]);
  24.  
  25.                 //-------------------------------------------------------------
  26.                 if (!TeamWormScore.ContainsKey(team))
  27.                 {
  28.                     TeamWormScore[team] = new Dictionary<string, decimal>();
  29.                 }
  30.                
  31.                 if (!wormExistList.Contains(wormName))
  32.                 {
  33.                     if (!TeamWormScore[team].ContainsKey(wormName))
  34.                     {
  35.                         TeamWormScore[team][wormName] = score;
  36.                     }
  37.                 }
  38.                 //-------------------------------------------------------------
  39.  
  40.                 wormExistList.Add(wormName);
  41.  
  42.                 inputLine = Console.ReadLine();
  43.             }
  44.  
  45.             int place = 1;
  46.             foreach (KeyValuePair<string, Dictionary<string, decimal>> teamScore in TeamWormScore
  47.                 .OrderByDescending(score => score.Value.Values.Sum())
  48.                 .ThenBy(sameScore => sameScore.Value.Keys.Count)
  49.                 .ThenBy(wormScore => wormScore.Value.Values.Max()))
  50.             {
  51.                 string team = teamScore.Key;
  52.                 decimal totalTeamScore = teamScore.Value.Values.Sum();
  53.                 Console.WriteLine($"{place}. Team: {team} - {totalTeamScore}");
  54.  
  55.                 foreach (KeyValuePair<string, decimal> wormScore in teamScore.Value
  56.                     .OrderByDescending(wormScore => wormScore.Value))
  57.                 {
  58.                     string wormName = wormScore.Key;
  59.                     decimal score = wormScore.Value;
  60.                     Console.WriteLine($"###{wormName} : {score}");
  61.                 }
  62.                 place++;
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement