n=int(input()) slowo=str(input()) tablica=[] tablica2=[] for i in slowo: tablica.append(i) tablica2.append(0) p=0 k=n-1 i=0 korekta_indeksu=0 while len(tablica)>2: if tablica[0]=="L": tablica.pop(0) p+=1 i=0 korekta_indeksu+=1 if tablica[-1]=="P": tablica.pop(-1) k-=1 i=0 if tablica[i]=="P" and tablica[i+1]=="L": tablica[i]="L" tablica[i+1]="P" tablica2[i + korekta_indeksu] += 1 tablica2[i + 1 + korekta_indeksu] += 1 i=0 elif tablica[i]=="L" and tablica[i+1]=="P": tablica[i]="P" tablica[i+1]="L" tablica2[i+korekta_indeksu]+=1 tablica2[i+1+korekta_indeksu]+=1 i=0 else: i+=1 for i in range(len(tablica2)-1): print(tablica2[i],end=" ") print(tablica2[-1])
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 | n=int(input()) slowo=str(input()) tablica=[] tablica2=[] for i in slowo: tablica.append(i) tablica2.append(0) p=0 k=n-1 i=0 korekta_indeksu=0 while len(tablica)>2: if tablica[0]=="L": tablica.pop(0) p+=1 i=0 korekta_indeksu+=1 if tablica[-1]=="P": tablica.pop(-1) k-=1 i=0 if tablica[i]=="P" and tablica[i+1]=="L": tablica[i]="L" tablica[i+1]="P" tablica2[i + korekta_indeksu] += 1 tablica2[i + 1 + korekta_indeksu] += 1 i=0 elif tablica[i]=="L" and tablica[i+1]=="P": tablica[i]="P" tablica[i+1]="L" tablica2[i+korekta_indeksu]+=1 tablica2[i+1+korekta_indeksu]+=1 i=0 else: i+=1 for i in range(len(tablica2)-1): print(tablica2[i],end=" ") print(tablica2[-1]) |