liczb = input() ants_movements = [] liczb = int(liczb) for i in range(liczb): move = input() ants_movements.append(move) ants_collision_lists = [0] * liczb def collided(i): if ants_movements[i] == "P" and i < liczb - 1: if collided(i+1): ants_collision_lists[i] += 1 ants_collision_lists[i+1] += 1 ants_movements[i:i+2] = "LP" return True else: return False elif ants_movements[i] == "L": return True return False for i in range(liczb): collided(i) for elem in ants_collision_lists: print(elem, end=" ")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | liczb = input() ants_movements = [] liczb = int(liczb) for i in range(liczb): move = input() ants_movements.append(move) ants_collision_lists = [0] * liczb def collided(i): if ants_movements[i] == "P" and i < liczb - 1: if collided(i+1): ants_collision_lists[i] += 1 ants_collision_lists[i+1] += 1 ants_movements[i:i+2] = "LP" return True else: return False elif ants_movements[i] == "L": return True return False for i in range(liczb): collided(i) for elem in ants_collision_lists: print(elem, end=" ") |