def mro(n, directions): result = [0] * int(n) idx = 0 while(True): found = directions.find('PL', idx) if idx > 0 and found == -1: idx = 0 continue if idx == 0 and found == -1: break result[found] += 1 result[found + 1] += 1 directions = directions[:found] + directions[found:].replace('PL', 'LP', 1) idx = found + 2 return ' '.join(str(x) for x in result) n = input() dir = input() print(mro(n, dir))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | def mro(n, directions): result = [0] * int(n) idx = 0 while(True): found = directions.find('PL', idx) if idx > 0 and found == -1: idx = 0 continue if idx == 0 and found == -1: break result[found] += 1 result[found + 1] += 1 directions = directions[:found] + directions[found:].replace('PL', 'LP', 1) idx = found + 2 return ' '.join(str(x) for x in result) n = input() dir = input() print(mro(n, dir)) |