Advertisement
KillianMills

maximumCupcakes.py

Oct 25th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import sys
  4.  
  5. # Complete the function below.
  6.  
  7.  
  8. # Sarah has 'n' dollar
  9. # Cupcake flat cost or 'c'
  10. # 1 free cupcake for every m cupcake wrappers
  11.  
  12.  
  13.  
  14. def maximumCupcakes(trips):
  15.    
  16.     for entry in trips:
  17.         split_entry = entry.split(" ")
  18.        
  19.         print(split_entry)
  20.         print(type(split_entry))
  21.         n = int(split_entry[0]) # 6
  22.         c = int(split_entry[1]) # 2
  23.         m = int(split_entry[2]) # 2
  24.        
  25.         cupcakes_with_wrappers = 0
  26.         wrappers = 0
  27.        
  28.         cupcakes_with_money = int(n / c) # initial wrappers # 6 / 2 = 3
  29.         wrappers = cupcakes_with_money # 3
  30.        
  31.         while(wrappers >= m): # accounting for multiple trips to the
  32.             cupcakes_with_wrappers =  cupcakes_with_wrappers + int(wrappers / m) # wrappers we get with our initial wrappers
  33.             wrappers = int(wrappers / m) + (wrappers % m)  # wrappers after buying with wrappers
  34.        
  35.         print(cupcakes_with_money + cupcakes_with_wrappers)
  36.  
  37.  
  38. if __name__ == "__main__":
  39.     trips_cnt = 0
  40.     trips_cnt = int(input())
  41.     trips_i = 0
  42.     trips = []
  43.     while trips_i < trips_cnt:
  44.         try:
  45.             trips_item = str(input())
  46.         except:
  47.             trips_item = None
  48.         trips.append(trips_item)
  49.         trips_i += 1
  50.  
  51.  
  52.     res = maximumCupcakes(trips);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement