Guest User

Untitled

a guest
Jun 27th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Numerics;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace ConsoleApp3
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var players = new Dictionary<string, Dictionary<string, long>>();
  16. var playersTotal = new Dictionary<string, long>();
  17. while (true)
  18. {
  19. string input = Console.ReadLine();
  20.  
  21. if (input == "Season end") break;
  22.  
  23. string[] inputArr = input.Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
  24.  
  25.  
  26. if (inputArr.Length > 1) // INPUT
  27. {
  28. string playerNmae = inputArr[0];
  29. string position = inputArr[1];
  30. long skill = long.Parse(inputArr[2]);
  31.  
  32. if (players.ContainsKey(playerNmae) == false)
  33. {
  34. players.Add(playerNmae, new Dictionary<string, long>());
  35. players[playerNmae].Add(position, skill);
  36. playersTotal.Add(playerNmae, skill);
  37. }
  38.  
  39. else if (players[playerNmae].ContainsKey(position))
  40. {
  41. if (players[playerNmae][position] < skill)
  42. {
  43. playersTotal[playerNmae] += skill - players[playerNmae][position];
  44. players[playerNmae][position] = skill;
  45. }
  46.  
  47. }
  48.  
  49. else
  50. {
  51. players[playerNmae].Add(position, skill);
  52. playersTotal[playerNmae] += skill;
  53. }
  54.  
  55.  
  56. }
  57.  
  58. else // BATTLE
  59. {
  60. string[] inputArr1 = input.Split(" vs ");
  61. string player1 = inputArr1[0];
  62. string player2 = inputArr1[1];
  63.  
  64. if (players.ContainsKey(player1) && players.ContainsKey(player2))
  65. {
  66. foreach (var kvplayer1 in players[player1])
  67. {
  68. foreach (var kvplaer2 in players[player2])
  69. {
  70. if (kvplayer1.Key == kvplaer2.Key)
  71. {
  72.  
  73. if (players[player1].Sum(x => x.Value) > players[player2].Sum(x => x.Value))
  74. {
  75. players.Remove(player2);
  76. playersTotal.Remove(player2);
  77. break;
  78. }
  79. else if (players[player1].Sum(x => x.Value) < players[player2].Sum(x => x.Value))
  80. {
  81. players.Remove(player1);
  82. playersTotal.Remove(player1);
  83. break;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92.  
  93. // OUTPUT
  94.  
  95. foreach (var kvp in playersTotal.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  96. {
  97. Console.WriteLine($"{kvp.Key}: {kvp.Value} skill");
  98.  
  99.  
  100. foreach (var pos in players[kvp.Key].OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  101. {
  102. Console.WriteLine($"- {pos.Key} <::> {pos.Value}");
  103. }
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment