Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- green_light = int(input())
- window = int(input())
- cars = deque()
- cars_counter = 0
- crashed = False
- command = input()
- while command != "END":
- if command == "green":
- if cars:
- current = cars.popleft()
- seconds_left = green_light - len(current)
- while seconds_left > 0:
- cars_counter += 1
- if cars:
- current = cars.popleft()
- seconds_left -= len(current)
- else:
- break
- if seconds_left == 0:
- cars_counter += 1
- if window >= abs(seconds_left):
- if seconds_left < 0:
- cars_counter += 1
- else:
- idx = window + seconds_left
- print("A crash happened!")
- print(f"{current} was hit at {current[idx]}.")
- crashed = True
- break
- else:
- cars.append(command)
- command = input()
- if not crashed:
- print("Everyone is safe.")
- print(f"{cars_counter} total cars passed the crossroads.")
Add Comment
Please, Sign In to add comment