Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 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 DictMoreExc3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var league = new Dictionary<string, Dictionary<string, int>>();
  14. var PlayersAndPoints = new Dictionary<string, int>();
  15. while (true)
  16. {
  17. string command = Console.ReadLine();
  18. if (command == "Season end")
  19. {
  20. foreach (var item in league.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(x => x.Key))
  21. {
  22. Console.WriteLine($"{item.Key}: {item.Value.Values.Sum()} skill");
  23. foreach (var item2 in item.Value.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  24. {
  25. Console.WriteLine($"- {item2.Key} <::> {item2.Value}");
  26. }
  27. }
  28. break;
  29. }
  30.  
  31. if (command.Contains("->"))
  32. {
  33. var split = command.Split(new string[] { " -> " }, StringSplitOptions.None);
  34. string name = split[0];
  35. string role = split[1];
  36. int points = int.Parse(split[2]);
  37. if (!league.ContainsKey(name))
  38. {
  39. league.Add(name, new Dictionary<string, int>());
  40. league[name].Add(role, points);
  41. PlayersAndPoints.Add(name, points);
  42. }
  43. if (league.ContainsKey(name))
  44. {
  45. if (league[name].ContainsKey(role))
  46. {
  47. if (league[name][role] < points)
  48. {
  49. league[name][role] = points;
  50. PlayersAndPoints[name] = points;
  51. }
  52. }
  53. else
  54. {
  55. league[name].Add(role, points);
  56. PlayersAndPoints[name] += points;
  57. }
  58. }
  59. }
  60. if (command.Contains("vs"))
  61. {
  62. var split = command.Split(new string[] { " vs " }, StringSplitOptions.None);
  63. string attacker = split[0];
  64. string attacked = split[1];
  65. string currentRole = string.Empty;
  66. bool succesfulAttack = false;
  67. if (league.ContainsKey(attacker) && league.ContainsKey(attacked))
  68. {
  69. foreach (var item in league[attacker].Keys)
  70. {
  71. foreach (var item2 in league[attacked].Keys)
  72. {
  73. if (item == item2)
  74. {
  75. succesfulAttack = true;
  76. currentRole += item;
  77. break;
  78. }
  79. }
  80. if (succesfulAttack == true)
  81. {
  82. break;
  83. }
  84. }
  85. }
  86. if (succesfulAttack == true)
  87. {
  88. if (league[attacked].Values.Sum() > league[attacker].Values.Sum())
  89. {
  90. league.Remove(attacker);
  91. }
  92. else if (league[attacked].Values.Sum() < league[attacker].Values.Sum())
  93. {
  94. league.Remove(attacked);
  95. }
  96.  
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement