← 返回 amazon 的题目列表Manage Party Playlist with Person and Party Classes
类型:online_judge
Design two classes: Person and Party. The Party class is responsible for managing a playlist for a party. The playlist consists of songs recommended by each person attending the party. Implement efficient operations to: 1. Add a person to the party; 2. Remove a person from the party; 3. Recommend songs for a person; 4. Get the current playlist ordered by the number of recommendations and recommendation order.
Input:
Each person's name (string) and a list of recommended songs (string list);
A series of operations (add/remove person, recommend songs).
Output:
The result of executing each operation, especially when retrieving the current playlist.
Example:
Party p = Party()
Person a = Person('Alice')
a.recommend(['Song1', 'Song3'])
p.add_person(a)
Person b = Person('Bob')
b.recommend(['Song2'])
p.add_person(b)
p.get_playlist() # ['Song1', 'Song3', 'Song2']
b.recommend(['Song3'])
p.get_playlist() # ['Song3', 'Song1', 'Song2']
Example
Input
p = Party()
a = Person('Alice')
a.recommend(['Song1', 'Song2'])
p.add_person(a)
b = Person('Bob')
b.recommend(['Song2', 'Song3'])
p.add_person(b)
print(p.get_playlist())