Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P01.Ranking
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, string> coursesPassword = new Dictionary<string, string>();
  12. string command = Console.ReadLine();
  13. while (command != "end of contests")
  14. {
  15. string[] input = command.Split(':').ToArray();
  16. string course = input[0];
  17. string password = input[1];
  18. coursesPassword[course] = password;
  19. command = Console.ReadLine();
  20. }
  21. // Dictionary<string, int> userPoints = new Dictionary<string, int>();
  22. Dictionary<string, Dictionary<string, int>> userCoursePoints = new Dictionary<string, Dictionary<string, int>>();
  23. command = Console.ReadLine();
  24. while (command != "end of submissions")
  25. {
  26. string[] input = command.Split("=>").ToArray();
  27. string course = input[0];
  28. string password = input[1];
  29. string user = input[2];
  30. int points = int.Parse(input[3]);
  31. if (coursesPassword.ContainsKey(course) && coursesPassword[course] == password)
  32. {
  33. if (!userCoursePoints.ContainsKey(user))
  34. {
  35. userCoursePoints.Add(user, new Dictionary<string, int>());
  36. userCoursePoints[user].Add(course, points);
  37. }
  38. else
  39. {
  40. if (!userCoursePoints[user].ContainsKey(course))
  41. {
  42. userCoursePoints[user].Add(course, points);
  43. }
  44. else
  45. {
  46. if (userCoursePoints[user][course] < points)
  47. {
  48. userCoursePoints[user][course] = points;
  49. }
  50. }
  51. }
  52. }
  53. command = Console.ReadLine();
  54. }
  55.  
  56. var userCP = userCoursePoints.OrderByDescending(x => x.Value.Values.Sum()).Take(1);
  57. int sum = 0;
  58. string name = string.Empty;
  59. foreach (var kvp in userCP)
  60. {
  61. name = kvp.Key;
  62. foreach (var item in kvp.Value)
  63. {
  64. sum += item.Value;
  65. }
  66. }
  67. Console.WriteLine($"Best candidate is {name} with total {sum} points.");
  68. Console.WriteLine("Ranking: ");
  69.  
  70. foreach (var kvp in userCoursePoints.OrderBy(x => x.Key))
  71. {
  72. Console.WriteLine(kvp.Key);
  73.  
  74. foreach (var item in kvp.Value.OrderByDescending(x => x.Value))
  75. {
  76. Console.WriteLine($"# {item.Key} -> {item.Value}");
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement