Loading...
TodorDaskalov avatar TodorDaskalov 2 Точки

07. Robotics

Моля за помощ, ако някой може да открие грешката ми в кода за тази задача. Максимума, който постигам е 83/100 точки. Грешката, която дава е при тест номер 4, но нещо пропускам и не мога да се досетя какво.

https://pastebin.com/V52bzBsw

https://judge.softuni.org/Contests/Compete/Index/1831#6

Условие: 

7.*Robotics

There is a robotics factory. The current project is assembly-line robots.

Each robot has a processing time – it is the time in seconds the robot needs to process a product. When a robot is free, it should take a product for processing and log its name, product, and processing start time.

Each robot processes a product coming from the assembly line. A product is coming from the line each second (so the first product should appear at [start time + 1 second]). If a product passes the line and there is not a free robot to take it, it should be queued at the end of the line again.

The robots are standing in the line in the order of their appearance.

Input

  • On the first line, you will receive the robots' names and their processing times in the format "robotName-processTime;robotName-processTime;robotName-processTime..."
  • On the second line, you will get the starting time in the format "hh:mm:ss"
  • Next, until the "End" command, you will get a product on each line.

Output

  • Every time a robot takes a product, you should print: "{robotName} - {product} [hh:mm:ss]"

Examples

Input

Output

ROB-15;SS2-10;NX8000-3

8:00:00

detail

glass

wood

apple

End

ROB - detail [08:00:01]

SS2 - glass [08:00:02]

NX8000 - wood [08:00:03]

NX8000 - apple [08:00:06]

ROB-8

7:59:59

detail

glass

wood

sock

End

ROB - detail [08:00:00]

ROB - wood [08:00:08]

ROB - glass [08:00:16]

ROB - sock [08:00:24]

Тагове:
0
Python Advanced 20/09/2022 02:22:42
valerielashvili avatar valerielashvili 47 Точки

Оставям и моето решение:

from collections import deque


robots = [
    {'name': name, 'process_time': int(time)}
    for name, time in (robot.split('-') for robot in input().split(';'))
]
h, m, s = map(int, input().split(':'))
current_time = h * 3600 + m * 60 + s
products = deque([])

for robot in robots:
    robot.update({'next_free_time': current_time})

while (product := input()) != 'End':
    products.append(product)

while products:
    current_time += 1
    product = products.popleft()

    for robot in robots:
        if robot['next_free_time'] <= current_time:
            robot['next_free_time'] = current_time + robot['process_time']

            # If processing goes past midnight wrap current_time back into a 24-hour clock
            t = current_time % (24 * 3600)
            h, m, s = t // 3600, (t % 3600) // 60, t % 60
            print(f"{robot['name']} - {product} [{h:02d}:{m:02d}:{s:02d}]")
            break
    else:
        products.append(product)

 

0
11/01/2026 00:09:25
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.