Advertisement
jbn6972

Untitled

Dec 28th, 2023
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from collections import defaultdict
  3. class SupermarketCheckout:
  4.     checkout_line = defaultdict(list)
  5.  
  6.     def on_customer_enter(self, customer_id, line_number, num_items):
  7.         self.checkout_line[customer_id].append(line_number)
  8.         self.checkout_line[customer_id].append(num_items)
  9.         pass
  10.  
  11.     def on_basket_change(self, customer_id, new_num_items):
  12.         if customer_id in self.checkout_line:
  13.             self.checkout_line[customer_id][1] = new_num_items
  14.         pass
  15.  
  16.     def on_line_service(self, line_number, num_processed_items):
  17.  
  18.         for cust in self.checkout_line:
  19.             lin = self.checkout_line[cust][0]
  20.  
  21.             if lin != line_number:
  22.                 continue
  23.  
  24.             items = self.checkout_line[cust][1]
  25.             val = max(items - num_processed_items,0)
  26.             self.checkout_line[cust][1] = val
  27.             if val == 0:
  28.                 self.on_customer_exit(cust)
  29.  
  30.  
  31.     def on_lines_service(self):
  32.         for cust in self.checkout_line:
  33.             items = self.checkout_line[cust][1]
  34.             if items > 0:
  35.                 items -= 1
  36.             self.checkout_line[cust][1] = items
  37.             if items == 0:
  38.                 self.on_customer_exit(cust)
  39.  
  40.     def on_customer_exit(self, customer_id):
  41.         # Don't change this implementation.
  42.         print(customer_id)
  43.  
  44.  
  45. smc = SupermarketCheckout()
  46. smc.on_customer_enter(123,1,5)
  47. smc.on_customer_enter(2,2,3)
  48. smc.on_lines_service()
  49. smc.on_customer_enter(3,1,2)
  50. smc.on_line_service(1,6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement