Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Problem_8._Ranking
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, string> contestInfo = new Dictionary<string, string>();
  12. var userInfo = new Dictionary<string, Dictionary<string, double>>();
  13.  
  14. while (true)
  15. {
  16. var input = Console.ReadLine().Split(":", StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.  
  18. var end = input[0];
  19. if (end == "end of contests")
  20. {
  21. break;
  22. }
  23. var contests = input[0];
  24.  
  25. var password = input[1];
  26.  
  27. if (!contestInfo.ContainsKey(contests))
  28. {
  29. contestInfo.Add(contests, password);
  30. }
  31. }
  32.  
  33. while (true)
  34. {
  35. var input = Console.ReadLine().Split("=>", StringSplitOptions.RemoveEmptyEntries).ToArray();
  36. var end = input[0];
  37.  
  38. if (end == "end of submissions")
  39. {
  40. break;
  41. }
  42. var contest = input[0];
  43.  
  44. var password = input[1];
  45.  
  46. var username = input[2];
  47.  
  48. var point = double.Parse(input[3]);
  49.  
  50. if (contestInfo.ContainsKey(contest) && contestInfo[contest].Contains(password))
  51. {
  52. if (!userInfo.ContainsKey(username))
  53. {
  54. userInfo[username] = new Dictionary<string, double>();
  55.  
  56. if (!userInfo[username].ContainsKey(contest))
  57. {
  58. userInfo[username].Add(contest, point);
  59. }
  60. else
  61. {
  62. double points = userInfo[username][contest];
  63.  
  64. if (points < point)
  65. {
  66. userInfo[username][contest] = points;
  67. }
  68. }
  69. }
  70. else
  71. {
  72. if (!userInfo[username].ContainsKey(contest))
  73. {
  74. userInfo[username].Add(contest, point);
  75. }
  76. else
  77. {
  78. double points = userInfo[username][contest];
  79.  
  80. if (points < point)
  81. {
  82. userInfo[username][contest] = points;
  83. }
  84. }
  85. }
  86. }
  87. }
  88.  
  89. double bestSum = 0;
  90. var user = string.Empty;
  91. foreach (var sum in userInfo)
  92. {
  93. var currentSum = sum.Value.Sum(x => x.Value);
  94. var currentUser = sum.Key;
  95. if (currentSum > bestSum)
  96. {
  97. bestSum = currentSum;
  98. user = currentUser;
  99. }
  100. }
  101.  
  102. Console.WriteLine($"Best candidate is {user} with total {bestSum} points.");
  103. userInfo = userInfo.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value.OrderByDescending(y => y.Value).ToDictionary(y => y.Key, y => y.Value));
  104.  
  105.  
  106. Console.WriteLine("Ranking:");
  107.  
  108. foreach (var items in userInfo)
  109. {
  110. var username = items.Key;
  111.  
  112. Console.WriteLine(username);
  113. foreach (var item in items.Value)
  114. {
  115. Console.WriteLine($"# {item.Key} -> {item.Value}");
  116. }
  117. }
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement