n = int(input()) licznik = [0 for i in range(n)] mrowki = list(input()) prop = [False for i in range(n)] while mrowki != prop: temp = [] for i, mrowka in enumerate(mrowki): if mrowka: if mrowka == 'L': if i != 0 and mrowki[i-1]: licznik[i] += 1 temp.append('P') else: temp.append(False) else: if i != n-1 and mrowki[i+1]: licznik[i] += 1 temp.append('L') else: temp.append(False) else: temp.append(False) mrowki = temp print(' '.join(str(i) for i in licznik))
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 | n = int(input()) licznik = [0 for i in range(n)] mrowki = list(input()) prop = [False for i in range(n)] while mrowki != prop: temp = [] for i, mrowka in enumerate(mrowki): if mrowka: if mrowka == 'L': if i != 0 and mrowki[i-1]: licznik[i] += 1 temp.append('P') else: temp.append(False) else: if i != n-1 and mrowki[i+1]: licznik[i] += 1 temp.append('L') else: temp.append(False) else: temp.append(False) mrowki = temp print(' '.join(str(i) for i in licznik)) |