Advertisement
simeonshopov

Robotics

May 19th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. from collections import deque
  2.  
  3. robots_info = input().split(';')
  4. start_time = list(map(int, input().split(':')))
  5. time = sum([start_time[0]*60*60, start_time[1]*60, start_time[2]])
  6.  
  7. robots = {}
  8. new_robots = {}
  9.  
  10. products = deque()
  11.  
  12. def get_time(t: int):
  13.     seconds = t % 60
  14.     hours = (t // 60) // 60
  15.     minutes = (t // 60) - hours * 60
  16.     seconds_print = f'0{seconds}'if seconds < 10 else seconds
  17.     minutes_print = f'0{minutes}' if minutes < 10 else minutes
  18.     hours_print = f'0{hours}' if hours < 10 else hours
  19.     return f'{hours_print}:{minutes_print}:{seconds_print}'
  20.  
  21. while True:
  22.     command = input()
  23.     if command == 'End':
  24.         break
  25.     product = command
  26.     products.append(product)
  27.  
  28. for x in robots_info:
  29.     key, value = x.split('-')
  30.     robots.update({key: [int(value), time + robots_info.index(x) +1, 0]})
  31.  
  32. update = False
  33.  
  34. while True:
  35.     product = products[0]
  36.     if robots:
  37.         robot = [x for x in list(robots) if robots[x][2] == 0]
  38.         if robot:
  39.             robot = robot[0]
  40.             print(f'{robot} - {product} [{get_time(robots[robot][1])}]')
  41.             new_robots.update({robot: robots[robot]})
  42.             del robots[robot]
  43.             products.popleft()
  44.             if not products:
  45.                 break
  46.     else:
  47.         products.append(products.popleft())
  48.     for x in new_robots:
  49.         new_robots[x][1] += 1
  50.         new_robots[x][2] += 1
  51.         if new_robots[x][1] == 86400:
  52.             new_robots[x][1] = 0
  53.         if new_robots[x][2] == new_robots[x][0]:
  54.             new_robots[x][2] = 0
  55.             robots.update({x: new_robots[x]})
  56.             update = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement