SimeonTs

SUPyF Exam 10.03.2019 - 03. Listmons DB

Aug 13th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. """
  2. Basics OOP Principles
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/1511#2
  4.  
  5. SUPyF Exam 10.03.2019 - 03. Listmons DB
  6.  
  7. Problem:
  8. Input / Constraints
  9. Listmon is as like a Google. It tracks every of its players in the game. You beat It in its own game,
  10. so It asks you now to help It with the database and make several reports for It, because it is a mess there.
  11. You will start receiving players data in format:
  12. {playerName} -> {resultOfTheGame}, {resultOfTheGame}, {resultOfTheGame}, {resultOfTheGame} ...
  13. Keep in mind that it is possible to have two players with the same playerName. You should store the data separately,
  14. not replacing it.
  15. Every line is different data and different player.
  16. You must store it until you receive command 'report'. After that you will receive reporting tickets in format:
  17. • score descending
  18. • score ascending
  19. • numberOfGames descending
  20. • numberOfGames ascending
  21. Output
  22. * If you receive 'score descending' you must print all players by the order of the score descending,
  23. after that by name ascending in format:
  24.     {name}: {score}
  25. * If you receive 'score ascending' you must print all players by the order of the score ascending,
  26. after that by name ascending in format:
  27.     {name}: {score}
  28. * If you receive 'number of games descending' you must print all players by the number of games played descending,
  29. after that by name ascending in format:
  30.     {name}: {count of the games}
  31. * If you receive 'number of games ascending’  you must print all players by the number of games played ascending
  32. after that by name ascending in format:
  33.     {name}: {count of the games}
  34.  
  35. Examples:
  36.  
  37. Input:
  38. Sims -> 15, 25, 65, 85
  39. Misho -> 5, 5, 5
  40. Azzi -> 0, 0, 2, 5
  41. Sims -> 5, 5, 5, 5, 5, 5, 5
  42. report
  43. score ascending
  44. end
  45.  
  46. Output:
  47. Azzi: 7
  48. Misho: 15
  49. Sims: 35
  50. Sims: 190
  51.  
  52. Input:
  53. theBest -> 952, 26, 83, 15, 25
  54. ultimatePlayer -> 1998, 0, 25
  55. nick_name -> 25, 0, 9852648
  56. report
  57. numberOfGames descending
  58. numberOfGames ascending
  59. end
  60.  
  61. Output:
  62. theBest: 5
  63. nick_name: 3
  64. ultimatePlayer: 3
  65. nick_name: 3
  66. ultimatePlayer: 3
  67. theBest: 5
  68. """
  69.  
  70.  
  71. class Player:
  72.     def __init__(self, name: str, score: int, games: int):
  73.         self.name = name
  74.         self.score = score
  75.         self.games = games
  76.  
  77.  
  78. all_players = []
  79.  
  80. while True:
  81.     data = input()
  82.     if data == "report":
  83.         break
  84.     name_player, all_scores = data.split(" -> ")
  85.     scores_in_list = [int(item) for item in all_scores.split(", ")]
  86.     total_score = sum(scores_in_list)
  87.     games_played = len(scores_in_list)
  88.     player = Player(name=name_player, score=total_score, games=games_played)
  89.     all_players += [player]
  90.  
  91. while True:
  92.     command = input()
  93.     if command == "end":
  94.         break
  95.  
  96.     elif command == "score descending":
  97.         score_d_list = sorted(sorted(all_players, key=lambda x: x.name), key=lambda x: x.score, reverse=True)
  98.         for player in score_d_list:
  99.             print(f"{player.name}: {player.score}")
  100.  
  101.     elif command == "score ascending":
  102.         score_a_list = sorted(sorted(all_players, key=lambda x: x.name), key=lambda x: x.score)
  103.         for player in score_a_list:
  104.             print(f"{player.name}: {player.score}")
  105.  
  106.     elif command == "numberOfGames descending":
  107.         games_d_list = sorted(sorted(all_players, key=lambda x: x.name), key=lambda x: x.games, reverse=True)
  108.         for player in games_d_list:
  109.             print(f"{player.name}: {player.games}")
  110.  
  111.     elif command == "numberOfGames ascending":
  112.         games_a_list = sorted(sorted(all_players, key=lambda x: x.name), key=lambda x: x.games)
  113.         for player in games_a_list:
  114.             print(f"{player.name}: {player.games}")
Add Comment
Please, Sign In to add comment