A service publishes real-time data about freshly available concert tickets before anybody else. To be fast, they publish the information packet by packet.
Your bucket list contains concerts for the artists you want to see (on_receive_requirements
function). You have also decided that you are willing to pay up to a certain ticket price, but no more. Finally, concerts are only worth going to with friends, so you want to buy at least a certain number of available seats per concert.
The service will send AvailableTicket messages split into multiple packets. The service also provides an API to submit an Order to buy a ticket. Orders must also be sent packet by packet.
AvailableTicket Message Format
Packet 1: Message ID and Artist ID
Packet 2: Message ID and Ticket Price
Packet 3: Message ID and Available Seats
Notes
message_id
is the same for all packets of the same message.message_id
is unique and is not reused.- The order of packets for a given
message_id
is guaranteed, but packets from different messages may be interleaved.
Order Response Format
Packet 1: Artist ID
Packet 2: Number of seats to purchase
Task
Write a program to listen to available tickets and buy tickets matching your criteria as soon as they become available.
Complete the following functions
class ConcertTickets:
def __init__(self):
pass
def on_receive_requirements(self, artist_id, max_price, min_seats):
pass
def process_packet(self, message_id, data) -> int:
# return int to send Order response packet. 0 if nothing to send.
pass
This program should efficiently track available tickets and submit an order as soon as a ticket matches the given requirements.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
