Advertisement
Guest User

Untitled

a guest
Jun 18th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _6.Courses
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. string command = string.Empty;
  12. Dictionary<string, Dictionary<string, int>> courseRegister = new Dictionary<string, Dictionary<string, int>>();
  13. Dictionary<string, Dictionary<string, int>> usersStats = new Dictionary<string, Dictionary<string, int>>();
  14. SortedDictionary<string, int> totalPointsByUser = new SortedDictionary<string, int>();
  15.  
  16. while ((command = Console.ReadLine()) != "no more time")
  17. {
  18. string[] inputArg = command.Split(" -> ");
  19. string user = inputArg[0];
  20. string course = inputArg[1];
  21. int points = int.Parse(inputArg[2]);
  22.  
  23. if (!usersStats.ContainsKey(user))
  24. {
  25. usersStats.Add(user, new Dictionary<string, int>());
  26.  
  27. }
  28.  
  29. if (!usersStats[user].ContainsKey(course))
  30. {
  31. usersStats[user].Add(course, points);
  32. }
  33.  
  34.  
  35. if (usersStats[user][course] < points)
  36. {
  37. usersStats[user][course] = points;
  38. }
  39.  
  40.  
  41.  
  42. AddNewUser(courseRegister, user, course, points);
  43. }
  44.  
  45. foreach (var user in usersStats)
  46. {
  47. totalPointsByUser.Add(user.Key, 0);
  48.  
  49. foreach (var item in user.Value)
  50. {
  51. totalPointsByUser[user.Key] += item.Value;
  52. }
  53. }
  54.  
  55. foreach (var course in courseRegister)
  56. {
  57. int counter = 1;
  58. Console.WriteLine($"{course.Key}: {course.Value.Count} participants");
  59.  
  60. foreach (var user in course.Value.OrderByDescending(x => x.Value).ThenBy(x=>x.Key))
  61. {
  62. Console.WriteLine($"{counter++}. {user.Key} <::> {user.Value}");
  63. }
  64. }
  65.  
  66. Console.WriteLine("Individual standings:");
  67.  
  68.  
  69. int counter1 = 1;
  70. foreach (var user in totalPointsByUser.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  71. {
  72. Console.WriteLine($"{counter1++}. {user.Key} -> {user.Value}");
  73. }
  74. }
  75.  
  76. private static void AddNewUser(Dictionary<string, Dictionary<string, int>> courseRegister, string user, string course, int points)
  77. {
  78. if (!courseRegister.ContainsKey(course))
  79. {
  80. courseRegister.Add(course, new Dictionary<string, int>());
  81. }
  82.  
  83.  
  84. if (!courseRegister[course].ContainsKey(user))
  85. {
  86.  
  87. courseRegister[course].Add(user, points);
  88. }
  89.  
  90.  
  91. if (courseRegister[course][user] < points)
  92. {
  93. courseRegister[course][user] = points;
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement