Advertisement
Kaloyankerr

07. Robotics

Sep 17th, 2020
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def next_second(h, m, s):
  5.     s += 1
  6.     if s >= 60:
  7.         s = 0
  8.         m += 1
  9.         if m >= 60:
  10.             m = 0
  11.             h += 1
  12.             if h >= 24:
  13.                 h = 0
  14.  
  15.     return [h, m, s]
  16.  
  17.  
  18. def are_any_robots_available(robots_waiting):
  19.     for robot in sorted(robots_waiting):
  20.         robot[1] -= 1
  21.  
  22.         if robot[1] == 0:
  23.             robots.append([robot[0], robots_dict[robot[0]]])
  24.  
  25.     return list(filter(lambda x: x[1] > 0, robots_waiting))
  26.  
  27.  
  28. # robots = [x.split("-") for x in input().split(";")]
  29. robots = deque([[x[0], int(x[1])] for x in [x.split("-") for x in input().split(";")]])
  30. robots_dict = {x: y for (x, y) in robots}
  31. robots_unavailable = deque()
  32.  
  33. time = list(map(int, input().split(":")))
  34.  
  35. product = input()
  36. products = deque()
  37.  
  38. while product != "End":
  39.     products.append(product)
  40.     product = input()
  41.  
  42. while products:
  43.     time = next_second(time[0], time[1], time[2])
  44.     robots_unavailable = are_any_robots_available(robots_unavailable)
  45.     current_product = products.popleft()
  46.  
  47.     if robots:
  48.         current_robot = robots.popleft()
  49.         print(f"{current_robot[0]} - {current_product} [{time[0]:02d}:{time[1]:02d}:{time[2]:02d}]")
  50.         robots_unavailable.append(current_robot)
  51.  
  52.     else:
  53.         products.append(current_product)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement