SimeonTs

SUPyF2 Dict-More-Ex. - 02. Judge

Oct 26th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.32 KB | None | 0 0
  1. """
  2. Dictionaries - More Exercises
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1738#1
  4.  
  5. SUPyF2 Dict-More-Ex. - 02. Judge
  6.  
  7. Problem:
  8. You know the jude system, right?! Your job is to create a program similar to the Judge system.
  9. You will receive several input lines in one of the following formats:
  10. {username} -> {contest} -> {points}
  11. The constestName and username are strings, the given points will be an integer number.
  12. You need to keep track of every contest and individual statistics of every user.
  13. You should check if such contest already exists, and if not, add it,
  14. otherwise check if the current user Is participating in the contest, if he is participating take the higher score,
  15. otherwise just add it.
  16. Also you need to keep individual statistics for each user - the total points of all constests.
  17. You should end your program when you receive the command "no more time".
  18. At that point you should print each contest in order of input,
  19. for each contest print the participants ordered by points in desecending order, than ordered by name in ascending order.
  20. After that, you should print individual statistics for every participant ordered by total points in desecnding order,
  21. and then by alphabetical order.
  22. Input / Constraints
  23. • The input comes in the form of commands in one of the formats specified above.
  24. • Username and contest name always will be one word.
  25. • Points will be an integer will be an integer in range [0, 1000].
  26. • There will be no invalid input lines.
  27. • If all sorting criteria fail, the order should be by order of input.
  28. • The input ends when you receive the command "no more time".
  29. Output
  30. • The output format for the contests is:
  31. {constestName}: {participants.Count} participants
  32. {position}. {username} <::> {points}
  33. • After you print all contests, print the individual statistics for every participant.
  34. • The output format is:
  35. Individual standings:
  36. {position}. {username} -> {totalPoints}
  37. Examples:
  38. Input:
  39. Pesho -> Algo -> 400
  40. Gosho -> Algo -> 300
  41. Stamat -> Algo -> 200
  42. Pesho -> DS -> 150
  43. Mimi -> DS -> 600
  44. no more time
  45.  
  46. Output:
  47. Algo: 3 participants
  48. 1. Pesho <::> 400
  49. 2. Gosho <::> 300
  50. 3. Stamat <::> 200
  51. DS: 2 participants
  52. 1. Mimi <::> 600
  53. 2. Pesho <::> 150
  54. Individual standings:
  55. 1. Mimi -> 600
  56. 2. Pesho -> 550
  57. 3. Gosho -> 300
  58. 4. Stamat -> 200
  59.  
  60. Input:
  61. Pesho -> OOP -> 350
  62. Gosho -> OOP -> 250
  63. Stamat -> Advanced -> 600
  64. Gosho -> OOP -> 300
  65. Prakash -> OOP -> 300
  66. Prakash -> Advanced -> 250
  67. Ani -> JSCore -> 400
  68. no more time
  69.  
  70. Output:
  71. OOP: 3 participants
  72. 1. Pesho <::> 350
  73. 2. Gosho <::> 300
  74. 3. Prakash <::> 300
  75. Advanced: 2 participants
  76. 1. Stamat <::> 600
  77. 2. Prakash <::> 250
  78. JSCore: 1 participants
  79. 1. Ani <::> 400
  80. Individual standings:
  81. 1. Stamat -> 600
  82. 2. Prakash -> 550
  83. 3. Ani -> 400
  84. 4. Pesho -> 350
  85. 5. Gosho -> 300
  86. """
  87. contests = {}
  88. individual_standings = {}
  89.  
  90. while True:
  91.     # Getting the input sorted
  92.     command = input().split(" -> ")
  93.     if command[0] == "no more time":
  94.         break
  95.     username = command[0]
  96.     contest = command[1]
  97.     points = int(command[2])
  98.  
  99.     # Filling the contests dictionary
  100.     if contest not in contests:
  101.         contests[contest] = {username: points}
  102.     elif contest in contests:
  103.         if username not in contests[contest]:
  104.             contests[contest][username] = points
  105.         elif username in contests[contest]:
  106.             if points > contests[contest][username]:
  107.                 contests[contest][username] = points
  108.  
  109. # Filling the individual standings dictionary:
  110. for contest, value in contests.items():
  111.     for username, points in value.items():
  112.         if username not in individual_standings:
  113.             individual_standings[username] = points
  114.         elif username in individual_standings:
  115.             individual_standings[username] += points
  116.  
  117. # Printing the contests, sorted as required.
  118. for contest, value in contests.items():
  119.     print(f"{contest}: {len(value)} participants")
  120.     number = 1
  121.     for name, score in sorted(value.items(), key=lambda x: (-x[1], x[0])):
  122.         print(f"{number}. {name} <::> {score}")
  123.         number += 1
  124.  
  125. # Printing the individual standings, sorted as required.
  126. print("Individual standings:")
  127. position = 1
  128. for user, score in sorted(individual_standings.items(), key=lambda x: (-x[1], x[0])):
  129.     print(f"{position}. {user} -> {score}")
  130.     position += 1
Add Comment
Please, Sign In to add comment