n = int(input()) s = input() s_array = [-1] * n for direction in range(0, len(s)): if s[direction] == 'P': s_array[direction] = 1 results = [] results = [-1 for i in range(n)] start_cord = 0 end_cord = n-1 while(start_cord<end_cord): start_ant = s_array[start_cord] while start_cord<=n-1 and start_ant==-1: results[start_cord] = results[start_cord]+1 start_cord += 1 if start_cord<n: start_ant = s_array[start_cord] end_ant = s_array[end_cord] while end_cord>=0 and end_ant==1: results[end_cord] = results[end_cord]+1 end_cord -= 1 end_ant = s_array[end_cord] for ant in range(start_cord, end_cord): if s_array[ant] == 1 and s_array[ant+1] == -1: s_array[ant] *= -1 results[ant] +=1 s_array[ant+1] *= -1 results[ant+1] +=1 ant+=1 print(" ".join(str(x) for x in results))
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | n = int(input()) s = input() s_array = [-1] * n for direction in range(0, len(s)): if s[direction] == 'P': s_array[direction] = 1 results = [] results = [-1 for i in range(n)] start_cord = 0 end_cord = n-1 while(start_cord<end_cord): start_ant = s_array[start_cord] while start_cord<=n-1 and start_ant==-1: results[start_cord] = results[start_cord]+1 start_cord += 1 if start_cord<n: start_ant = s_array[start_cord] end_ant = s_array[end_cord] while end_cord>=0 and end_ant==1: results[end_cord] = results[end_cord]+1 end_cord -= 1 end_ant = s_array[end_cord] for ant in range(start_cord, end_cord): if s_array[ant] == 1 and s_array[ant+1] == -1: s_array[ant] *= -1 results[ant] +=1 s_array[ant+1] *= -1 results[ant+1] +=1 ant+=1 print(" ".join(str(x) for x in results)) |