Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Ranking
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. var contests = new Dictionary<string, string>();
  12. var users = new Dictionary<string, Dictionary<string, int>>();
  13. string firstInput = string.Empty;
  14.  
  15. while ((firstInput = Console.ReadLine()) != "end of contests")
  16. {
  17. string[] firstCommand = firstInput.Split(":");
  18. string password = firstCommand[1];
  19. string contestName = firstCommand[0];
  20.  
  21. if (!contests.ContainsKey(password))
  22. {
  23. contests[password] = contestName;
  24. }
  25.  
  26. }
  27. string secondInput = string.Empty;
  28.  
  29. while ((secondInput = Console.ReadLine()) != "end of submissions")
  30. {
  31. string[] secondCommand = secondInput.Split("=>");
  32. string contest = secondCommand[0];
  33. string password = secondCommand[1];
  34. string user = secondCommand[2];
  35. int point = int.Parse(secondCommand[3]);
  36.  
  37. if (contests.ContainsKey(password) && contests[password] == contest)
  38. {
  39. if (!users.ContainsKey(user))
  40. {
  41. users[user] = new Dictionary<string, int>();
  42. users[user][contest] = point;
  43. }
  44. if (users[user].ContainsKey(contest))
  45. {
  46.  
  47. if (users[user][contest] < point)
  48. {
  49. users[user][contest] = point;
  50. }
  51. }
  52. else
  53. {
  54. users[user][contest] = point;
  55. }
  56.  
  57. }
  58. else
  59. {
  60. continue;
  61. }
  62.  
  63.  
  64.  
  65. }
  66.  
  67. var userPointsSum = new Dictionary<string, int>();
  68.  
  69. foreach (var item in users)
  70. {
  71. userPointsSum[item.Key] = item.Value.Values.Sum();
  72. }
  73.  
  74. string bestName = userPointsSum.Keys.Max();
  75. int bestPoints = userPointsSum.Values.Max();
  76.  
  77. foreach (var item in userPointsSum)
  78. {
  79. if (item.Value == bestPoints)
  80. {
  81. Console.WriteLine($"Best candidate is {item.Key} with total {item.Value} points.");
  82. }
  83. }
  84.  
  85. Console.WriteLine("Ranking: ");
  86.  
  87. foreach (var item in users.OrderBy(x => x.Key))
  88. {
  89. Console.WriteLine(item.Key);
  90.  
  91. foreach (var kvp in item.Value.OrderByDescending(x=>x.Value))
  92. {
  93. Console.WriteLine($"# {kvp.Key} -> {kvp.Value}");
  94. }
  95. }
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement