Guest User

02_Judge

a guest
Dec 9th, 2018
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. namespace P02._Judge
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. class StartUp
  8. {
  9. public static void Main()
  10. {
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15.  
  16. namespace Test
  17. {
  18. class Program
  19. {
  20. static void Main(string[] args)
  21. {
  22. Dictionary<string, Dictionary<string, int>> userCoursePoints = new Dictionary<string, Dictionary<string, int>>();
  23. Dictionary<string, Dictionary<string, int>> courseUserPoints = new Dictionary<string, Dictionary<string, int>>();
  24. string command = Console.ReadLine();
  25. while (command != "no more time")
  26. {
  27. string[] input = command.Split(" -> ").ToArray();
  28. string course = input[1];
  29. string user = input[0];
  30. int points = int.Parse(input[2]);
  31.  
  32. //check if such contest already exists
  33. if (!courseUserPoints.ContainsKey(course))
  34. {
  35. courseUserPoints.Add(course, new Dictionary<string, int>());
  36. }
  37. //if user not exist
  38. if (!courseUserPoints[course].ContainsKey(user))
  39. {
  40. courseUserPoints[course][user] = 0;
  41. }
  42. // if he is taking the higher score
  43. if (courseUserPoints[course][user] < points)
  44. {
  45. courseUserPoints[course][user] = points;
  46. }
  47.  
  48. //Add course to user
  49. if (!userCoursePoints.ContainsKey(user))
  50. {
  51. userCoursePoints.Add(user, new Dictionary<string, int>());
  52. }
  53. //if course not exist
  54. if (!userCoursePoints[user].ContainsKey(course))
  55. {
  56. userCoursePoints[user][course] = 0;
  57. }
  58. // if he is taking the higher score
  59. if (userCoursePoints[user][course] < points)
  60. {
  61. userCoursePoints[user][course] = points;
  62. }
  63.  
  64. command = Console.ReadLine();
  65. }
  66.  
  67. List<string> result = new List<string>();
  68. foreach (var kvp in courseUserPoints)
  69. {
  70. result.Add($"{kvp.Key}: {kvp.Value.Count()} participants");
  71. int counter = 0;
  72.  
  73. var sortedCourses = kvp.Value.OrderByDescending(x => x.Value).ThenBy(u=>u.Key);
  74. foreach (var item in sortedCourses)
  75. {
  76. counter++;
  77. result.Add($"{counter}. {item.Key} <::> {item.Value}");
  78. }
  79.  
  80. }
  81. result.Add("Individual standings:");
  82. int count = 0;
  83.  
  84. var sortedUsers = userCoursePoints.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(x => x.Key);
  85. foreach (var kvp in sortedUsers)
  86. {
  87. count++;
  88. result.Add($"{count}. {kvp.Key} -> {kvp.Value.Values.Sum()}");
  89. }
  90. //Join by new line - Environment.NewLine or "\n"
  91. Console.WriteLine(string.Join(Environment.NewLine, result));
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment