Advertisement
Guest User

Untitled

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