Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def adding_cars(command_input, cars_line):
- while command_input != "END":
- cars_line.append(command_input)
- command_input = input()
- return cars_line
- def car_crashing(current_car, green_light_sec, free_window_sec):
- green_light_sec += free_window_sec
- character_hit = current_car[green_light_sec]
- print(f"A crash happened!\n{current_car} was hit at {character_hit}.")
- green_light = int(input())
- free_window = int(input())
- command = input()
- cars_deque = deque()
- curr_green_light = green_light
- total_cars_passed = 0
- adding_cars(command, cars_deque)
- while cars_deque:
- curr_el = cars_deque.popleft()
- if curr_el != "green" and curr_green_light > 0:
- if len(curr_el) == curr_green_light:
- total_cars_passed += 1
- curr_green_light = 0
- elif len(curr_el) < curr_green_light:
- total_cars_passed += 1
- curr_green_light -= len(curr_el)
- elif curr_green_light > 0 and len(curr_el) <= curr_green_light + free_window:
- total_cars_passed += 1
- curr_green_light = 0
- else:
- car_crashing(curr_el, curr_green_light, free_window)
- break
- elif curr_el == "green":
- curr_green_light = green_light
- else:
- print(f"Everyone is safe.\n{total_cars_passed} total cars passed the crossroads.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement