Advertisement
bullit3189

MOBAChallenger-MyProblemDecision

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