Advertisement
bullit3189

MOBA Challenger - Dictionaries

Jan 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _03MOBAChallenger
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<string, int>> playerPositionSkill = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (command == "Season end")
  18. {
  19. break;
  20. }
  21.  
  22. if (command.Contains("->"))
  23. {
  24. string[] tokens = command.Split(" -> ");
  25.  
  26. string player = tokens[0];
  27. string position = tokens[1];
  28. int skill = int.Parse(tokens[2]);
  29.  
  30. if (!playerPositionSkill.ContainsKey(player))
  31. {
  32. playerPositionSkill.Add(player, new Dictionary<string, int>());
  33. playerPositionSkill[player].Add(position, skill);
  34. }
  35. else if (playerPositionSkill.ContainsKey(player)==true && playerPositionSkill[player].ContainsKey(position)==false)
  36. {
  37. playerPositionSkill[player].Add(position, skill);
  38. }
  39. else if (playerPositionSkill.ContainsKey(player) && playerPositionSkill[player].ContainsKey(position))
  40. {
  41. if (playerPositionSkill[player][position]<skill)
  42. {
  43. playerPositionSkill[player][position] = skill;
  44. }
  45. }
  46. }
  47. else
  48. {
  49. string[] tokens = command.Split(" vs ");
  50.  
  51. string player1 = tokens[0];
  52. string player2 = tokens[1];
  53.  
  54. if (playerPositionSkill.ContainsKey(player1) && playerPositionSkill.ContainsKey(player2))
  55. {
  56. string[] player1Positions = playerPositionSkill[player1].Keys.ToArray();
  57.  
  58. foreach (var player2Positions in playerPositionSkill[player2].Keys)
  59. {
  60. if (player1Positions.Contains(player2Positions))
  61. {
  62. int totalSkillPointsPlayer1 = playerPositionSkill[player1].Values.Sum();
  63. int totalSkillPointsPlayer2 = playerPositionSkill[player2].Values.Sum();
  64.  
  65. if (totalSkillPointsPlayer1>totalSkillPointsPlayer2)
  66. {
  67. playerPositionSkill.Remove(player2);
  68. break;
  69. }
  70. else if (totalSkillPointsPlayer1 < totalSkillPointsPlayer2)
  71. {
  72. playerPositionSkill.Remove(player1);
  73. break;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80.  
  81. foreach (var kvp in playerPositionSkill.OrderByDescending(x=>x.Value.Values.Sum()).ThenBy(x=>x.Key))
  82. {
  83. string player = kvp.Key;
  84. int totalSkill = kvp.Value.Values.Sum();
  85. Console.WriteLine($"{player}: {totalSkill} skill");
  86.  
  87. foreach (var kvpValue in kvp.Value.OrderByDescending(y=>y.Value).ThenBy(y=>y.Key))
  88. {
  89. string position = kvpValue.Key;
  90. int skill = kvpValue.Value;
  91. Console.WriteLine($"- {position} <::> {skill}");
  92. }
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement