Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Enter your code here. Read input from STDIN. Print output to STDOUT
- from collections import defaultdict
- class SupermarketCheckout:
- checkout_line = defaultdict(list)
- def on_customer_enter(self, customer_id, line_number, num_items):
- self.checkout_line[customer_id].append(line_number)
- self.checkout_line[customer_id].append(num_items)
- pass
- def on_basket_change(self, customer_id, new_num_items):
- if customer_id in self.checkout_line:
- self.checkout_line[customer_id][1] = new_num_items
- pass
- def on_line_service(self, line_number, num_processed_items):
- for cust in self.checkout_line:
- lin = self.checkout_line[cust][0]
- if lin != line_number:
- continue
- items = self.checkout_line[cust][1]
- val = max(items - num_processed_items,0)
- self.checkout_line[cust][1] = val
- if val == 0:
- self.on_customer_exit(cust)
- def on_lines_service(self):
- for cust in self.checkout_line:
- items = self.checkout_line[cust][1]
- if items > 0:
- items -= 1
- self.checkout_line[cust][1] = items
- if items == 0:
- self.on_customer_exit(cust)
- def on_customer_exit(self, customer_id):
- # Don't change this implementation.
- print(customer_id)
- smc = SupermarketCheckout()
- smc.on_customer_enter(123,1,5)
- smc.on_customer_enter(2,2,3)
- smc.on_lines_service()
- smc.on_customer_enter(3,1,2)
- smc.on_line_service(1,6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement