IPetrov007

WWPartyRumi

May 15th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 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 Problem_4___Worms_World_Party
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var result = new Dictionary<string, Dictionary<string, long>>();
  14. var line = Console.ReadLine();
  15. while (line != "quit")
  16. {
  17. var tokens = line.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19. var wName = tokens[0];
  20. var teamName = tokens[1];
  21. var score = long.Parse(tokens[2]);
  22. var hasW = false;
  23. foreach (var kvp in result)
  24. {
  25. if (kvp.Value.ContainsKey(wName))
  26. {
  27. hasW = true;
  28. }
  29. }
  30. if (!hasW)
  31. {
  32.  
  33. if (!result.ContainsKey(teamName))
  34. {
  35. result[teamName] = new Dictionary<string, long>();
  36. }
  37. if (!result[teamName].ContainsKey(wName))
  38. {
  39. result[teamName].Add(wName, 0L);
  40.  
  41. }
  42. result[teamName][wName] += score;
  43. }
  44. line = Console.ReadLine();
  45. }
  46. var count = 1;
  47. foreach (var kvp in result.OrderByDescending(x => x.Value.Sum(y => y.Value))
  48. .ThenByDescending(x => x.Value.Sum(y => y.Value) / x.Value.Count()))
  49.  
  50. {
  51.  
  52. var totalScore = kvp.Value.Sum(x => x.Value);
  53. Console.WriteLine("{0}. Team: {1} - {2}", count, kvp.Key, totalScore);
  54. count++;
  55. foreach (var wNameScore in kvp.Value.OrderByDescending(x => x.Value))
  56. {
  57. var wName = wNameScore.Key;
  58. var score = wNameScore.Value;
  59. Console.WriteLine("###{0} : {1}", wName, score);
  60. }
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment