Advertisement
SimeonTs

SUPyF2 Dict-More-Ex. - 01. Ranking

Oct 26th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.93 KB | None | 0 0
  1. """
  2. Dictionaries - More Exercises
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1738#0
  4.  
  5. SUPyF2 Dict-More-Ex. - 01. Ranking
  6.  
  7. Problem:
  8. Here comes the final and the most interesting part – the Final ranking of the candidate-interns.
  9. The final ranking is determined by the points of the interview tasks and from the exams in SoftUni.
  10. Here is your final task. You will receive some lines of input in the format
  11. "{contest}:{password for contest}" until you receive "end of contests". Save that data because you will need it later.
  12. After that you will receive other type of inputs in format "{contest}=>{password}=>{username}=>{points}"
  13. until you receive "end of submissions". Here is what you need to do.
  14. • Check if the contest is valid (if you received it in the first type of input)
  15. • Check if the password is correct for the given contest
  16. • Save the user with the contest they take part in (a user can take part in many contests)
  17. and the points the user has in the given contest. If you receive the same contest and the same user
  18. update the points only if the new ones are more than the older ones.
  19. At the end you have to print the info for the user with the most points in the format
  20. "Best candidate is {user} with total {total points} points.".
  21. After that print all students ordered by their names.
  22. For each user print each contest with the points in descending order. See the examples.
  23. Input
  24. • strings in format "{contest}:{password for contest}" until the "end of contests" command.
  25. There will be no case with two equal contests
  26. • strings in format "{contest}=>{password}=>{username}=>{points}" until the "end of submissions" command.
  27. • There will be no case with 2 or more users with same total points!
  28. Output
  29. • On the first line print the best user in format "Best candidate is {user} with total {total points} points.".
  30. • Then print all students ordered as mentioned above in format:
  31. {user1 name}
  32. #  {contest1} -> {points}
  33. #  {contest2} -> {points}
  34. Constraints
  35. • the strings may contain any ASCII character except from (:, =, >)
  36. • the numbers will be in range [0 - 10000]
  37. • second input is always valid
  38. Examples:
  39. Input:
  40. Part One Interview:success
  41. Js Fundamentals:Pesho
  42. C# Fundamentals:fundPass
  43. Algorithms:fun
  44. end of contests
  45. C# Fundamentals=>fundPass=>Tanya=>350
  46. Algorithms=>fun=>Tanya=>380
  47. Part One Interview=>success=>Nikola=>120
  48. Java Basics Exam=>pesho=>Petkan=>400
  49. Part One Interview=>success=>Tanya=>220
  50. OOP Advanced=>password123=>BaiIvan=>231
  51. C# Fundamentals=>fundPass=>Tanya=>250
  52. C# Fundamentals=>fundPass=>Nikola=>200
  53. Js Fundamentals=>Pesho=>Tanya=>400
  54. end of submissions
  55.  
  56. Output:
  57. Best candidate is Tanya with total 1350 points.
  58. Ranking:
  59. Nikola
  60. #  C# Fundamentals -> 200
  61. #  Part One Interview -> 120
  62. Tanya
  63. #  Js Fundamentals -> 400
  64. #  Algorithms -> 380
  65. #  C# Fundamentals -> 350
  66. #  Part One Interview -> 220
  67.  
  68. Input:
  69. Java Advanced:funpass
  70. Part Two Interview:success
  71. Math Concept:asdasd
  72. Java Web Basics:forrF
  73. end of contests
  74. Math Concept=>ispass=>Monika=>290
  75. Java Advanced=>funpass=>Simona=>400
  76. Part Two Interview=>success=>Drago=>120
  77. Java Advanced=>funpass=>Petyr=>90
  78. Java Web Basics=>forrF=>Simona=>280
  79. Part Two Interview=>success=>Petyr=>0
  80. Math Concept=>asdasd=>Drago=>250
  81. Part Two Interview=>success=>Simona=>200
  82. end of submissions
  83.  
  84. Output:
  85. Best candidate is Simona with total 880 points.
  86. Ranking:
  87. Drago
  88. #  Math Concept -> 250
  89. #  Part Two Interview -> 120
  90. Petyr
  91. #  Java Advanced -> 90
  92. #  Part Two Interview -> 0
  93. Simona
  94. #  Java Advanced -> 400
  95. #  Java Web Basics -> 280
  96. #  Part Two Interview -> 200
  97. """
  98. contests = {}
  99. users = {}
  100.  
  101. while True:
  102.     command = input().split(":")
  103.     if command[0] == "end of contests":
  104.         break
  105.     contests[command[0]] = command[1]
  106.  
  107. while True:
  108.     command = input().split("=>")
  109.     if command[0] == "end of submissions":
  110.         break
  111.     contest = command[0]
  112.     password = command[1]
  113.     username = command[2]
  114.     points = int(command[3])
  115.     if contest in contests:
  116.         if contests[contest] == password:
  117.             if username not in users:
  118.                 users[username] = {contest: points}
  119.             elif username in users:
  120.                 if contest not in users[username]:
  121.                     users[username].update({contest: points})
  122.                 elif contest in users[username]:
  123.                     if points > users[username][contest]:
  124.                         users[username][contest] = points
  125.  
  126. best_candidate = ["", 0]
  127. for user, scores in users.items():
  128.     sum_score = sum(scores.values())
  129.     if sum_score >= best_candidate[1]:
  130.         best_candidate[0], best_candidate[1] = user, sum_score
  131.  
  132. print(f"Best candidate is {best_candidate[0]} with total {best_candidate[1]} points.")
  133. print(f"Ranking: ")
  134. for user, content in sorted(users.items(), key=lambda x: x):
  135.     print(user)
  136.     for contest, points in sorted(users[user].items(), key=lambda x: -x[1]):
  137.         print(f"#  {contest} -> {points}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement