Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApp2
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15.  
  16. var dict = new Dictionary<string, Dictionary<string, int>>();
  17. bool isRemoved = false;
  18. var input = string.Empty;
  19. while ((input = Console.ReadLine()) != "Season end")
  20. {
  21. isRemoved = false;
  22. if (input.Contains("->"))
  23. {
  24. var tokens = input.Split(new string[] {" -> "}, StringSplitOptions.RemoveEmptyEntries).ToList();
  25. var player = tokens[0];
  26. var position = tokens[1];
  27. var skill = int.Parse(tokens[2]);
  28. if (!dict.ContainsKey(player))
  29. {
  30. dict[player]=new Dictionary<string, int>();
  31. dict[player][position] = skill;
  32.  
  33. }else if (dict.ContainsKey(player))
  34. {
  35. if (!dict[player].ContainsKey(position))
  36. {
  37. dict[player][position] = skill;
  38. }else if (dict[player].ContainsKey(position))
  39. {
  40. foreach (var ch in dict)
  41. {
  42. var playr = ch.Key;
  43. if (player == playr)
  44. {
  45. var postns = ch.Value;
  46. foreach (var ps in postns)
  47. {
  48. if (ps.Key == position)
  49. {
  50. if (ps.Value < skill)
  51. {
  52. dict[player][position] = skill;
  53. }
  54. }
  55. }
  56. }
  57. }
  58.  
  59. }
  60. }
  61. }
  62. else if (input.Contains("vs"))
  63. {
  64. var tokens = input.Split(new string[] { " vs " }, StringSplitOptions.RemoveEmptyEntries).ToList();
  65. var playerOne = tokens[0];
  66. var playerTwo = tokens[1];
  67. if (dict.ContainsKey(playerOne) && dict.ContainsKey(playerTwo))
  68. {
  69. foreach (var h in dict)
  70. {
  71. if (h.Key == playerOne)
  72. {
  73. foreach (var t in h.Value)
  74. {
  75. if (dict[playerTwo].ContainsKey(t.Key))
  76. {
  77. var playerOneSum = 0;
  78. var playertwoSum = 0;
  79. foreach (var m in dict)
  80. {
  81.  
  82. if (playerOne == m.Key)
  83. {
  84. foreach (var p in m.Value)
  85. {
  86. playerOneSum = m.Value.Values.Sum();
  87. }
  88. }
  89. else if (playerTwo == m.Key)
  90. {
  91. foreach (var p in m.Value)
  92. {
  93. playertwoSum = m.Value.Values.Sum();
  94. }
  95. }
  96. }
  97.  
  98. if (playerOneSum > playertwoSum)
  99. {
  100. dict.Remove(playerTwo);
  101. isRemoved = true;
  102. break;
  103. }
  104. else if (playertwoSum > playerOneSum)
  105. {
  106. dict.Remove(playerOne);
  107. isRemoved = true;
  108. break;
  109. }
  110. }
  111.  
  112. }
  113.  
  114. if (isRemoved)
  115. {
  116. break;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123.  
  124. foreach (var plrs in dict.OrderByDescending(x=>x.Value.Values.Sum()).ThenBy(x=>x.Key))
  125. {
  126. var name = plrs.Key;
  127. var pos = plrs.Value;
  128. Console.WriteLine($"{name}: {plrs.Value.Values.Sum()} skill");
  129. foreach (var n in pos.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  130. {
  131. Console.WriteLine($"- {n.Key} <::> {n.Value}");
  132. }
  133. }
  134. }
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement